How can i check whether the browser is active or not in crossrider? -


i need calculate browser using time in extension. if can check whether browser active or not, easy calculate time. how possible in crossrider?

var focused = true; window.onfocus = window.onblur = function(e) {     focused = (e || event).type === "focus"; } alert(focused); 

i tried code in background.js display "true" if minimize browser window.

the focus , blur events not available in background scope of extension, ones not using crossrider.

the common solution use extension scope (extension.js) detect events , pass information background page using messaging.

using code base, following example should achieve goal:

extension.js

appapi.ready(function($) {   window.onfocus = window.onblur = function(e) {     appapi.message.tobackground({       focus: (e || event).type === "focus"     });   } }); 

background.js

appapi.ready(function($) {   appapi.message.addlistener(function(msg) {     console.log('focus: '+msg.focus);   }); }); 

[diclosure: crossrider employee]


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -