#14399 closed bug (notabug)
jQuery does no binding for visibilitychange events in Chrome
Reported by: | 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.
Change History (4)
comment:1 Changed 9 years ago by
comment:2 Changed 9 years ago by
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
Resolution: | → notabug |
---|---|
Status: | new → closed |
comment:4 Changed 9 years ago by
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.
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