If you actually need to add a <param>
(as opposed to adjusting an attribute value), I've discovered that grabbing the <object>
, cloning it, adding the <param>
and then replacing the current <object>
tag seems to work in most browsers (although it doesn't seem to work in Firefox). See this answer for a working example.
That linked answer is for every <object>
on a page, here is how you would do it for a single instance of the tag:
// create the appropriate <param>
var elementToAppend = document.createElement('param');
elementToAppend.setAttribute('name', 'src');
elementToAppend.setAttribute('value', 'blah.midi');
// get a reference to the <object>
var obj = document.getElementById('yourMidiPlayerObject');
// duplicate the <object>
var newObj = obj.cloneNode(true);
// append the <param> to the <object>
newObj.appendChild(elementToAppend);
// replace the <object> on the page
obj.parentNode.replaceChild(newObj, obj);
If the <param>
you want to modify already exists things are a bit different:
// get a reference to the <object>
var obj = document.getElementById('yourMidiPlayerObject');
// duplicate the <object>
var newObj = obj.cloneNode(true);
// get a reference to the current <param>
var param = document.getElementById('theParamId');
// duplicate the <param>
var newParam = param.cloneNode(true);
// change the value of the <param>
newParam.setAttribute('value', 'newblah.midi');
// replace the <param> tag on the <object>
newObj.replaceChild(newParam, param);
// replace the <object> on the page
obj.parentNode.replaceChild(newObj, obj);
In both cases, the trick to getting it working in IE, Opera, Safari and Chrome is to replace the <object>
on the page. Appending a new <param>
to the existing <object>
doesn't seem to make it reparse the value or load the newly referred to content.