1

I want to execute some code when user activate the browser's tab.

window.onfocus = function() {
  console.log('323');
};

On localhost this works, but doesn't work on remote server. Console is empty.

I also tried without success:

$(window).bind('focus', function() {
      console.log('323');
});​

My browser is Chrome, last version.

John Weisz
  • 26,986
  • 12
  • 84
  • 123
qadenza
  • 8,611
  • 18
  • 61
  • 108

1 Answers1

0

In Chrome you need to use the jQuery focus function:

$(window).focus(function () {
    console.log('ative');
});

$(window).focus(function () {
    console.log('ative');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Alexandre Neukirchen
  • 2,557
  • 7
  • 23
  • 34