Skip to main content

Bug Tracker

Side navigation

#14399 closed bug (notabug)

Opened September 29, 2013 11:23PM UTC

Closed October 13, 2013 12:26PM UTC

Last modified October 15, 2013 03:50AM UTC

jQuery does no binding for visibilitychange events in Chrome

Reported by: tomprogramming@gmail.com Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 2.0.3
Keywords: Cc:
Blocked by: Blocking:
Description

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.

Attachments (0)
Change History (4)

Changed September 30, 2013 12:43AM UTC by dmethvin comment:1

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.

https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview.html

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

http://docs.webplatform.org/wiki/dom/navigator/maxTouchPoints

Changed September 30, 2013 01:18PM UTC by tomprogramming@gmail.com comment:2

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

Thanks for the info.

Changed October 13, 2013 12:26PM UTC by dmethvin comment:3

resolution: → notabug
status: newclosed

Changed October 15, 2013 03:50AM UTC by dcherman comment:4

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.