Unable to set document.body.innerHTML of IFrame
Categories
(Core :: DOM: Core & HTML, defect, P3)
Tracking
()
Webcompat Priority | P3 |
People
(Reporter: theosib, Unassigned)
References
(Depends on 1 open bug)
Details
(Whiteboard: [webcompat][needs-wpt-?])
Attachments
(3 files)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22 Steps to reproduce: I'm using the nightly, and I've looked for a cross-browser way to programmatically set the innerHTML of an IFrame. (As in http://roneiv.wordpress.com/2008/01/18/get-the-content-of-an-iframe-in-javascript-crossbrowser-solution-for-both-ie-and-firefox/). This is what I wrote: <html> <body> <div name=FRAME2div id=FRAME2div style="position:absolute; background-color:blue; color:black; border-color:black;border-width:0; left:100px; top:40px; width:200px; height:200px; overflow:scroll; display:block; " > </div> <script type="text/javascript"> document.getElementById("FRAME2div").innerHTML = '<iframe border=0 id=IFRAME2 name=IFRAME2 ></iframe>'; document.getElementById("IFRAME2").contentWindow.document.body.innerHTML = '<html><body><p>NETSCAPE</p></body></html>'; </script> </body> </html> Actual results: It works fine in Safari and Chrome, but not in the latest nightly of Firefox. Expected results: I should see the word "NETSCAPE" appear in the blue box.
Reporter | ||
Comment 1•13 years ago
|
||
Someone suggested I access the innerHTML this way: frames['IFRAME2'].document.documentElement.innerHTML = '<html><body><p>NETSCAPE</p></body></html>'; But that doesn't work either.
Confirming on Win XP and FF10a1. Interestingly, after loading the page, running the command: document.getElementById("IFRAME2").contentWindow.document.body.innerHTML = '<html><body><p>NETSCAPE</p></body></html>'; from the Web Console does work.
Updated•13 years ago
|
Comment 4•13 years ago
|
||
I think the reason is because the document inside your iframe isn't created yet. You should wait for the load event before setting something inside the iframe. I'm going to attach an example that is working.
Comment 5•13 years ago
|
||
Comment 6•13 years ago
|
||
Henri, do we plan to follow what Webkit is doing here or should we WONTFIX this? (or DUPE maybe?)
Comment 7•13 years ago
|
||
(In reply to Mounir Lamouri (:volkmar) (:mounir) from comment #6) > Henri, do we plan to follow what Webkit is doing here or should we WONTFIX > this? I expect us to follow WebKit/spec here eventually. Marking as dependent on bug 543435.
Reporter | ||
Comment 8•13 years ago
|
||
Someone suggested a workaround for this. Before setting the innerHTML, we can trigger a false load. Here's the new version that works, without needing to wait for an unload, which would be inconvenient for the real application (my code here is just the essential parts that demonstrate the problem): <html> <body> <div name=FRAME2div id=FRAME2div style="position:absolute; background-color:blue; color:black; border-color:black;border-width:0; left:100px; top:40px; width:200px; height:200px; overflow:scroll; display:block; " > </div> <script type="text/javascript"> document.getElementById("FRAME2div").innerHTML = '<iframe border=0 id=IFRAME2 name=IFRAME2 ></iframe>'; doc = frames["IFRAME2"].document; doc.open(); doc.close(); doc.body.innerHTML = '<html><body><p>NETSCAPE</p></body></html>'; </script> </body> </html> I got the suggestion from here: http://stackoverflow.com/questions/7828502/cannot-set-document-body-innerhtml-of-iframe-in-firefox
Comment 9•9 years ago
|
||
any news for this? As you can see http://output.jsbin.com/yipemaweha this in Firefox not work, in chrome there are no problem.
Comment 10•6 years ago
|
||
This long-standing interop issue is still affecting sites adversely, so it's probably worth reconsidering its priority again after all this time.
Updated•6 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Comment 11•5 years ago
|
||
Migrating Webcompat whiteboard priorities to project flags. See bug 1547409.
Comment 12•5 years ago
|
||
See bug 1547409. Migrating whiteboard priority tags to program flags.
Comment 13•5 years ago
|
||
(In reply to Henri Sivonen (:hsivonen) from comment #7)
(In reply to Mounir Lamouri (:volkmar) (:mounir) from comment #6)
Henri, do we plan to follow what Webkit is doing here or should we WONTFIX
this?I expect us to follow WebKit/spec here eventually. Marking as dependent on
bug 543435.
Henri, is it the HTML standard that (should?) defines this?
Updated•5 years ago
|
Comment 14•5 years ago
|
||
(In reply to Mike Taylor [:miketaylr] (PTO July 31 - Aug 8) from comment #13)
Henri, is it the HTML standard that (should?) defines this?
This is in the HTML Standard, but a quick look suggests the level of detail is insufficient (about events):
https://html.spec.whatwg.org/#creating-a-new-browsing-context
Updated•5 years ago
|
Updated•4 years ago
|
Updated•4 years ago
|
Comment 15•4 years ago
|
||
(In reply to Henri Sivonen (:hsivonen) from comment #14)
(In reply to Mike Taylor [:miketaylr] (PTO July 31 - Aug 8) from comment #13)
Henri, is it the HTML standard that (should?) defines this?
This is in the HTML Standard, but a quick look suggests the level of detail is insufficient (about events):
https://html.spec.whatwg.org/#creating-a-new-browsing-context
has an issue been opened about it?
https://github.com/whatwg/html/issues
And probably Henri would correctly phrase the issue. Or thomas?
We just created an intervention for webcompat because of this issue
https://github.com/mozilla-extensions/webcompat-addon/pull/175/files
Comment 16•4 years ago
|
||
(In reply to Karl Dubost💡 :karlcow from comment #15)
has an issue been opened about it?
There is https://github.com/whatwg/html/issues/4965 from 2019.
Comment 17•4 years ago
|
||
This is somewhat less about the spec and more about what we can get done given our corpus of Gecko-specific test cases.
I already failed at fixing this in the summer of 2011. I now thing I understand the issues better, and part of my failure then was trying to fix too much at the same time.
My current thinking is that we should
- Change the docshell/content viewer-created
about:blank
from lazy to eager for the Web (keeping in lazy for XUL). - Change the ghost of the old HTML parser not to blow away the document created in step 1 and to make it only fire the relevant events.
Comment 18•4 years ago
|
||
Realistically, not going to happen while Fission requires the level of attention it is requiring right now.
Updated•2 years ago
|
Updated•2 years ago
|
Comment 19•1 year ago
|
||
Clear a needinfo that is pending on an inactive user.
Inactive users most likely will not respond; if the missing information is essential and cannot be collected another way, the bug maybe should be closed as INCOMPLETE
.
For more information, please visit auto_nag documentation.
Comment 20•1 year ago
|
||
Redirecting the ni? to the correct Tom-account.
Comment 21•1 year ago
|
||
I'm not sure what I can add here, aside from mentioning that we should probably revisit this again after bug 543435 lands, since it seems similar to the first option Henri mentioned in comment #17.
Comment 22•1 year ago
|
||
A workaround, as identified in https://stackoverflow.com/questions/8240101/set-content-of-iframe#comment20993503_8240158, is to set the src property:
<iframe src="javascript:void(0);"></iframe>
Comment 23•1 year ago
|
||
Description
•