Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#14399 closed bug (notabug)

jQuery does no binding for visibilitychange events in Chrome

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 2.0.3
Keywords: Cc:
Blocked by: Blocking:


According to http://caniuse.com/#feat=pagevisibility Chrome, Opera, and Blackberry browsers use the webkit prefix for the event "visbilitychange" that gets fired on the document

jQuery does not seem to handle this case when binding to the "visbilitychange" event. The workaround is to bind to both the visibilitychange and webkitvisibilitychange event. However, if/when Chrome decides to fire the correct event name, this may cause the event handler to fire twice, as it does in firefox when listening for both visibilitychange and mozvisibilitychange, which was the old interface for FF10 according to https://developer.mozilla.org/en-US/docs/Web/Reference/Events/visibilitychange

Example of the problem (Chrome): http://jsfiddle.net/tomprogramming/YCrJA/1/

Example of the workaround (Chrome): http://jsfiddle.net/tomprogramming/YCrJA/2/

Example of firefox firing twice (MUST use firefox to view): http://jsfiddle.net/tomprogramming/YCrJA/3/

It would be nice to just put in jQuery(document).on("visibilitychange", handler); and have it work in a manner similar to the mouseenter/mouseleave=>mouseover/mouseout handling.

Change History (4)

comment:1 Changed 9 years ago by dmethvin

This is a feature request. We've never tried to handle prefixed event names. Since the browser vendors seem to be (thankfully) swearing off anything prefixed in the future, prefixed events are more of a transitional issue that should disappear within a year.

For this particular case you can easily determine whether the standard event is handled since the browser unprefixes both the document.hidden property and the event names at the same time.


The same is true for events like MSPointerDown vs pointerdown, you can look for the navigator.maxTouchPoints.


comment:2 Changed 9 years ago by [email protected]

Fair enough, and that is a reasonable and stable workaround while Chrome and friends get their act together.

Thanks for the info.

comment:3 Changed 9 years ago by dmethvin

Resolution: notabug
Status: newclosed

comment:4 Changed 9 years ago by dcherman

Shameless self plug - you can easily accomplish unprefixing the event via the Special Event API. See https://github.com/dcherman/jquery.pagevisibility for an example of doing so.

Note: See TracTickets for help on using tickets.