Friday, August 22nd, 2008

HTML 5: The event loop, hashchange, and more

Category: HTML

Mark Pilgrim continues to keep us up to date with news in HTML 5 land. This week he talks to us about the birth of the event loop, and the hashchange event.

I saw this just after posting about the cross browser hashchange example by Zach Leatherman. In the future we will see a nice, standard way to do this work:

The other major news this week is the addition of the hashchange event, which occurs when the user clicks an in-page link that goes somewhere else on the same page, or when a script programmatically sets the location.hash property. This is primarily useful for AJAX applications that wish to maintain a history of user actions while remaining on the same page. As a concrete example, executing a search of your messages in GMail takes you to a list of search results, but does not change the URL, just the hash; clicking the Back button takes you back to the previous view within GMail (such as your inbox), again without changing the URL (just the hash). GMail employs some nasty hacks to make this work in all browsers; the hashchange event is designed to make those hacks slightly less nasty. Microsoft Internet Explorer 8 pioneered the hashchange event, and its definition in HTML 5 is designed to match Internet Explorer’s behavior.

Defining the event loop is a big deal:

The purpose of defining an event loop is to unify the definition of things that happen asychronously. (I want to avoid saying “events” since that term is already overloaded.) For example, if an image defines an onload callback function, exactly when does it get called? Questions like this are now answered in terms of queueing tasks in the event loop.

Thanks again to Mark for doing the work so we don’t have too. After seeing three episodes, it is interesting to see the velocity of changes in the spec. Kudos to the group for that.

Posted by Dion Almaer at 8:23 am
1 Comment

4.8 rating from 66 votes

1 Comment »

Comments feed TrackBack URI

Seems like IE’s implementation is based on the HTML 5 spec, and not the other way around:

Comment by Jeria — August 22, 2008

Leave a comment

You must be logged in to post a comment.