Friday, December 19th, 2008

This Week in HTML 5: onbeforeunload leading to script groups

Category: HTML

<p>Mark Pilgrim has a new episode of This Week in HTML 5 that covers the onbeforeunload event. To get there, a lot happened, which Hixie explained:

Someone asked for onbeforeunload, so I started fixing it. Then I found that there was some rot in the drywall. So I took down the drywall. Then I found a rat infestation. So I killed all the rats. Then I found that the reason for the rot was a slow leak in the plumbing. So I tried fixing the plumbing, but it turned out the whole building used lead pipes. So I had to redo all the plumbing. But then I found that the town’s water system wasn’t quite compatible with modern plumbing techniques, and I had to dig up the entire town. And that’s basically it.

After going into the detail of the actual unraveling, Mark gets to the skinny:

The most interesting part of this new definition is the script group, a new concept which now governs all scripts. When a Document is created, it gets a fresh script group, which contains all the scripts that are defined (or are later created somehow) in the document. When the user navigates away from the document, the entire script group is frozen, and browsers should not execute those scripts anymore. This sounds like an obvious statement if you think of documents as individual browser windows (or tabs), but consider the case of a document with multiple frames, or one with an embedded iframe. Suppose that the user clicks some link within the iframe that only navigates to a new URL within the iframe (i.e. the parent document stays the same). The parent document may have some reference to functions defined in the old iframe. Should it still be able to call these functions? IE says no; other browsers say yes. HTML 5 now says no, because when the iframe navigates to a new URL, the old iframes script group is frozen — even if there are active references to those scripts (say, from the parent document), browsers shouldn’t allow the page to execute them.

The main benefit of this new concept of script groups is that it removes a number of complications faced by the non-IE browsers. For example, it prevents the problem of scripts suddenly discovering that their global object is no longer the object that they think of as the Window object. Script groups are also frozen when calling document.open(). Freezing script groups also defines the point at which timers and other callbacks are reset, which is something that previous versions of HTML had never defined.

In related news, Jacob Gube has a guest post on RWW covering 5 Exciting Things to Look Forward to in HTML 5.

Related Content:

Posted by Dion Almaer at 8:12 am
3 Comments

+++--
3.5 rating from 12 votes

3 Comments »

Comments feed TrackBack URI

Yuck. Did I just read something about how having and (etc) tags will make things better? So am I to assume that the future will be like the past? Good grief. How about you use “class” to indicate the class of something? And if your layout is awesome, you will get millions of users, and the market will *force* other developers to follow your conventions? To put it another way: is it better to have jquery or spend 5 years rewriting javascript to have a $ operator? The rest of the changes highlighted by the article make much more sense.

Comment by nataxia — December 19, 2008

that was `header` and `footer` tags

Comment by nataxia — December 19, 2008

The first paragraph made me laugh out loud! The second one made me groan. Why more restrictions? It’s hard enough to deal with iframes. Maybe I’m okay if they give me enough tools that I don’t need to rely upon iframes.

Comment by AnM8tR — December 19, 2008

Leave a comment

You must be logged in to post a comment.