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
  • 30,137
  • 13
  • 89
  • 132
qadenza
  • 9,025
  • 18
  • 73
  • 126

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,713
  • 7
  • 26
  • 36