Search

Posts Tagged ‘jquery’

I love jQuery for many reasons, the primary one being that it abstracts all the cross-browser pain of writing plain old javascript away to a dark corner where I don’t have to look at it, and can instead focus on the positives of javascript (the same could be said for prototype, dojo, etc).

Until today, jQuery has performed admirably in this role, and has a  fantastic selection/manipulation to boot.  Until today.

You see, there’s this weird event called ‘beforeunload’, which triggers right as a user is navigating away from a page, but before they actually leave the page.  The sole purpose of this event is to confirm with the user that they want to leave, that they might lose unsaved changes, etc.  It’s not exactly a standard event: some browsers support it, some don’t, and the implementations can be subtly different.  So, naive me, I thought this would be a great place to use jQuery, and abstract away all that cross-browser pain that has bitten me so many times before.

No can do.  Craig Stuntz and I got into a brief discussion today on Twitter, and along with some googling and a quick spike that I did, I learned that jQuery has no truck with onbeforeunload, and if you want to use it, you’re stuck with plain old javascript and cross-browser pain.  Booo.  Fortunately, rare is the occasion where you should use this non-standard event (if ever).