javascript - Is there any way to detect that window is currently active in IE8? -


is there way detect window active (is being shown on active tab/window) in ie8?

i know there events onfocusin/onfocus - not perfect solution, since window must receive focus event fired - not work when user switches tabs without touching window itself.

i believe there has simple, elegant solution such ordinary use-case.

i’ve written jquery plugin this: http://mths.be/visibility gives simple api allows execute callbacks when page’s visibility state changes.

it using the page visibility api it’s supported, , falling old focus , blur in older browsers.

demo: http://mathiasbynens.be/demo/jquery-visibility

this plugin provides 2 custom events use: show , hide. when page visibility state changes, appropriate event triggered.

you can use them separately:

$(document).on('show', function() {   // page gained visibility }); 

…and…

$(document).on('hide', function() {   // page hidden }); 

since of time you’ll need both events, best option use events map. way, can bind both event handlers in 1 go:

$(document).on({   'show': function() {     console.log('the page gained visibility; `show` event triggered.');   },   'hide': function() {     console.log('the page lost visibility; `hide` event triggered.');   } }); 

the plugin detect if page visibility api natively supported in browser or not, , expose information boolean (true/false) in $.support.pagevisibility:

if ($.support.pagevisibility) {   // page visibility natively supported in browser } 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -