W3C home > Mailing lists > Public > whatwg@whatwg.org > August 2010

[whatwg] Should events be paused on detached iframes?

From: Ben Lerner <blerner@cs.washington.edu>
Date: Tue, 24 Aug 2010 13:30:03 -0700
Message-ID: <4C742BCB.1020006@cs.washington.edu>
  There seems to be a bit of disagreement among browsers about how event 
loops and iframes interact when an iframe is removed and then reinserted 
into its parent document.  Consider the following two documents: the 
parent document has a button that removes or reattaches an iframe to the 
document, while the second simply sets an interval to update the page 
content.

Page1.html:
<!DOCTYPE HTML>
<html>
<body>
<p><button onclick="toggleInDoc();">Show/hide</button></p>
<iframe id="test" src="page2.html"></iframe>
<script>
     var test = document.getElementById("test");
     function toggleInDoc() {
       if (test.parentNode == null)
         document.body.appendChild(test);
       else
         document.body.removeChild(test);
     }
</script>
</body>
</html>


Page2.html:
<!DOCTYPE HTML>
<html>
<body>
<p id="test"></p>
<script>
     window.setInterval(function() { 
document.getElementById("test").innerHTML += "."; }, 500);
</script>
</body>
</html>


Assume the user waits until the interval has fired several times, then 
presses the button, waits a while, and presses it again.  There are 
three possible outcomes:
1. When the iframe is reattached, the inner page reloads.  This seems to 
go beyond the wording of the spec, which says only "When an iframe 
element is first inserted into a document, the user agent must create a 
nested browsing context, and then process the iframe attributes for the 
first time."  (This isn't the first time the iframe is inserted into the 
document, so we shouldn't process the iframe attributes again.)

2. The interval (and presumably, all events) in the iframe is paused 
while it's been detached (since the document is no longer fully active, 
but it also has not been discarded because of the global reference to 
its container element).

3. The interval (and presumably, all events) continues to fire while 
it's been detached, and the content of page2 will have changed while 
it's been detached from page1.

So far, Chrome 6, Opera 10.6 and Firefox 3.6 follow #1, and IE 8 follows 
#3.  My reading of the "fully active" clause of the spec leads me to 
expect #2.  Which of these behaviors is the desired one?  And/or, would 
it be desirable to permit authors to specify which behavior they intend?

Thanks,
~ben
Received on Tuesday, 24 August 2010 13:30:03 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:09:00 UTC