miscoded

the web is a hack

Firefox's pageshow and pagehide events not DOM2 events-compatible?

, , , , ,

These events sound quite interesting and author friendly. But unless I'm missing something their current implementation in Firefox simply sucks!

I tried
document.addEventListener( 'pageShow', function(e){ log('pageshow fired'); }, false );
document.addEventListener( 'pageHide', function(e){ log('pagehide fired'); }, false );


No go. Then I tried window.addEventListener but that doesn't work either. Finally, I looked at the sample code and noticed it only shows DOM0-style event handlers -
<body onPageShow="..."
. yuck Really?? That makes the events pretty useless. I would like Opera to support similar events but Firefox's implementation looks too broken to copy. Tell me I'm missing something..

window.opener and security - an unfixable problem?quote of the day

Comments

Mark 'Tarquin' Wilton-Jonestarquinwj Wednesday, March 14, 2007 5:47:12 PM

Did you try adding the event listeners to the body instead of the document? Or perhaps the window instead? Remember that FF's DOM events are broken wrt document. They map body to window, and ignore the document.

João EirasxErath Wednesday, March 14, 2007 8:15:05 PM

Opera support DOMFocusIn and DOMFocusOut, which are enough.

sypasche Wednesday, March 14, 2007 8:40:54 PM

The event names are pageshow / pagehide (case sensitive). And they are dispatched to the window, not the document (http://lxr.mozilla.org/mozilla/source/layout/base/nsDocumentViewer.cpp#1245). So the correct code would be:

window.addEventListener( 'pageshow', function(e){ log('pageshow fired'); }, false );
window.addEventListener( 'pagehide', function(e){ log('pagehide fired'); }, false );

Hallvord R. M. Steenhallvors Thursday, March 15, 2007 12:52:34 PM

sypasche: thanks! smile I tried all lower case with document.addEventListener and then I tried camel case before trying window.addEventListener .. 8-)

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.