Copy Code code as follows:
<body>
<textarea></textarea>
Hello
<script>
Window.onblur=function () {
Document.title= ' blur: ' + math.random ();
}
Window.onfocus=function () {
Document.title= ' Focus: ' + math.random ();
}
</script>
</body>
This should be a very common requirement, for example, the current window periodically updates the data, and the window loses its focus to reduce the frequency of information updates. The pairing confusion caused by the IE6 bug will disrupt our plan.
Search on the internet did not find out about the official description of the bug and recommended solutions, had to be born more to achieve a solution.
The code is as follows:
Copy Code code as follows:
<body>
<textarea></textarea>
Hello
<script>
(function () {
var focustimer = 0;
function Myblur () {
Document.title= ' blur: ' + math.random ();
}
function Myfocus () {
Cleartimeout (Focustimer);
Focustimer = settimeout (function () {
Document.title = ' Focus: ' + math.random ();
},10);
}
Window.onfocus = Document.body.onfocusin = Myfocus;
Window.onblur = Document.body.onfocusout = Myblur;
}());
</script>
</body>
The basic principle is: to find a lot of opportunities that can trigger onfocus and onblur, all onblur are executed immediately, and onfocus delay 10 milliseconds for lazy execution.
The result: Although sometimes several myfocus and Myblur are performed, the correctness of the window state is ensured.
Method may be a little cottage, but the moment did not think of a better way, this can also temporarily solve a pressing.