You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<html>
<head>
</head>
<body>
<iframe src='bar.html' id='foo'></iframe>
(bar.html is just an empty file on the same domain)
<script>
var ifr = document.getElementById('foo')
alert(ifr.contentWindow)
</script>
</body>
On running through gdb it seems like childrenhere is an empty vector.
This happens to iframes created from source, from innerHTML, and from createElement()
Right. It seems that the creation of the frame's document and window is deferred until the content is fetched -- and if no src is ever set, no content is ever fetched.
If we set src to blank.html and instead fetch the contentWindow after a timeout, then it works fine.
Perhaps we should make the contentwindow getter block until the subpage exists? Have some sort of mutexy thing on the iframe that is locked when the fetch starts, and .contentWindow will block until it finishes.
Activity
Manishearth commentedon Apr 3, 2015
Update: this turns out to be because iframe loading is async, apparently
However,
i = document.createElement('iframe'); document.body.appendChild(i); i.contentWindowworks in Firefox, but not in Servo (still gives null)magcius commentedon Apr 3, 2015
Right. It seems that the creation of the frame's document and window is deferred until the content is fetched -- and if no src is ever set, no content is ever fetched.
If we set src to blank.html and instead fetch the contentWindow after a timeout, then it works fine.
According to https://html.spec.whatwg.org/multipage/embedded-content.html#the-iframe-element , iframes without a src should have the src "about:blank", which is an immediately-available resource that can never asynchronously load.
jdm commentedon Apr 3, 2015
Yes, sync about:blank is tracked at #5240.
Manishearth commentedon Aug 11, 2015
@sole has a nice example on #7162.
Perhaps we should make the contentwindow getter block until the subpage exists? Have some sort of mutexy thing on the iframe that is locked when the fetch starts, and
.contentWindowwill block until it finishes.jdm commentedon Aug 11, 2015
No, we should just implement synchronous about:blank rather than hacking around the lack of it. That's #5240.
Manishearth commentedon Aug 11, 2015
That's only for iframes without a src. What about iframes with a src that haven't loaded yet?
jdm commentedon Aug 11, 2015
Same deal. All iframes start with about:blank and then navigate to the src url.
Ms2ger commentedon Aug 18, 2015
#3924