i have an iframe and in javascript i enable the design mode as follows
iframe.contentDocument.designMode="on";
which works fine if i create my iframe inline. but if i load my iframe with a "src" attribute in my parent page and i turn on the design mode as follows:
iframes=document.getElementsByTagName('iframe');
for(iframe in iframes)
{
iframes[iframe].contentDocument.designMode="on";
}
then it doesnot work. how can i enable the iframe's design mode from the container page if im loading the iframe specifying the src attribute? not inline!! Thanks
i have an iframe and in javascript i enable the design mode as follows
iframe.contentDocument.designMode="on";
which works fine if i create my iframe inline. but if i load my iframe with a "src" attribute in my parent page and i turn on the design mode as follows:
iframes=document.getElementsByTagName('iframe');
for(iframe in iframes)
{
iframes[iframe].contentDocument.designMode="on";
}
then it doesnot work. how can i enable the iframe's design mode from the container page if im loading the iframe specifying the src attribute? not inline!! Thanks
Share Improve this question edited Aug 3, 2011 at 10:23 samach asked Aug 3, 2011 at 10:12 samachsamach 3,39410 gold badges43 silver badges54 bronze badges 2- Are you loading the iframe's contents from the same domain as the parent/containing site? If it's from a different site you will have no access to the DOM of the iframe. – Jon Grant Commented Aug 3, 2011 at 10:26
- yea im loading it from the same domian...and still i cant modify the contentDocument properties of the loaded iframe – samach Commented Aug 3, 2011 at 10:29
1 Answer
Reset to default 8Depending on the browser, there are a couple of potential issues:
- not all browsers (particularly older ones) support
contentDocument
for...in
is not guaranteed to work on aNodeList
, which is whatgetElementsByTagName()
returns. Usefor
loop instead.- you may need to wait for all of the iframes to load. The main document's
load
event will fire only once all the iframes have loaded.
Otherwise, so long as the iframe is served from the same domain, it is possible to set its document's designMode
property from the containing document. The following should work:
window.onload = function() {
var iframes = document.getElementsByTagName('iframe');
for (var i = 0, len = iframes.length, doc; i < len; ++i) {
doc = iframes[i].contentDocument || iframes[i].contentWindow.document;
doc.designMode = "on";
}
};