itay312
itay312

Reputation: 1568

How to detect if browser tab has changed and refresh it if so

I need a cross-browser javaScript code (if possible) that detects when entering a browser's tab (crossing from current opened tab to another tab) and refresh its page when the change was made.

Upvotes: 0

Views: 1089

Answers (1)

VadimB
VadimB

Reputation: 5711

Window events can be in handy. So you can react to the blur and focus events, so leaving your browser tab will cause blur event and returning back - focus event.

$(window).focus(function(){
  //refresh your page here
});

Upvotes: 1

Related Questions