hello
<script> <br>window.onblur=function(){ <br>document.title= 'blur:' Math.random() ; <br>} <br>window.onfocus =function(){ <br>document.title= 'focus:' Math.random() ; <br>} <br></script>
This should be a very common requirement, for example, the current window updates data regularly, while the window being out of focus reduces the information update frequency. The pairing confusion caused by IE6 bugs will disrupt our plans.
I couldn’t find any official description or recommended solution for this bug when I searched online, so I had to implement a solution myself.
The code is as follows:
hello
<script> <br>(function(){ <br>var focusTimer = 0; <br>function myBlur(){ <br>document. title= 'blur:' Math.random() ; <br>} <br>function myFocus(){ <br>clearTimeout(focusTimer); <br>focusTimer = setTimeout(function(){ <br>document.title = 'focus:' Math.random() ; <br>},10); <br>} <br>window.onfocus = document.body.onfocusin = myFocus; <br>window.onblur = document.body.onfocusout = myBlur; <br>}()); <br></script>
The general principle is: find many opportunities that may trigger onfocus and onblur, all The onblur is executed immediately, while the onfocus is executed lazily with a delay of 10 milliseconds.
The result is: although myFocus and myBlur are sometimes executed several times more, the correctness of the window status can be guaranteed.
The method may be a bit copycat, but I didn’t think of a better way for the time being, so this can temporarily solve an urgent need.