IE6 the solution of focus and blur disorder _javascript skills

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.