Skip to content Skip to sidebar Skip to footer

Setting The Base Tag Of A Dynamically Created Iframe

I'm trying to dynamically create an iframe and set it's base tag before it is created. ifrm = document.createElement('IFRAME'); ifrm.setAttribute('src', 'test.html'); ifrm.style.

Solution 1:

You can append a <base> element to ifrm.contentDocument.getElementsByTagName("head").

You'll need to create it in the child document by calling ifrm.contentDocument.createElement("base")

For example:

var bt = ifrm.contentDocument.createElement("base");
bt.setAttribute(...);
ifrm.contentDocument.getElementsByTagName("head")[0].appendChild(bt);

Post a Comment for "Setting The Base Tag Of A Dynamically Created Iframe"