[whatwg] History: onpopstate on initial document load
glenn at zewt.org
Wed Aug 15 21:17:41 PDT 2012
Should this alert on initial load?
<!doctype html><body onpopstate="alert('xxx')">
 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  "update the
session history with the new page", which invokes  "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.
More information about the whatwg