[whatwg] History: onpopstate on initial document load

Glenn Maynard glenn at zewt.org
Wed Aug 15 21:17:41 PDT 2012

Should this alert on initial load?

<!doctype html><body onpopstate="alert('xxx')">

[1] says "After creating the Document object, but before any script
execution, certainly before the parser stops, the user agent must update
the session history with the new page."  That invokes [2] "update the
session history with the new page", which invokes [3] "Traverse the history
to the new entry", which fires popstate in step 14.

However, "After creating the Document object, but before any script
execution" seems like it could happen before or after the <body> element
has been parsed, so the alert may or may not happen.

Whether it's always invoked or never invoked, it would be least confusing
for it to match up with:

<!doctype html><script>window.onpopstate = alert("xxx");</script>

so either both of the above or neither of the above alert.  From what I can
tell, this one should never alert on load, since the script doesn't run
until after the popstate event has already happened.

WebKit alerts in both of these cases (and after onload).  Firefox and Opera
alert in neither.

[1] http://www.whatwg.org/specs/web-apps/current-work/#read-html
[3] http://www.whatwg.org/specs/web-apps/current-work/#traverse-the-history

Glenn Maynard

More information about the whatwg mailing list