Solution to confusion between focus and blur in IE6 _ javascript skills

Source: Internet
Author: User
The IE6bug detected by Miller is as follows: When you click textarea, The blur of the window is triggered, resulting in confusion between the focus and blur pairs. The Code is as follows:




Hello
Script
Window. onblur = function (){
Document. title = 'blur: '+ Math. random ();
}
Window. onfocus = function (){
Document. title = 'focus: '+ Math. random ();
}
Script


This should be a very common requirement. For example, the current window regularly updates data, while the window de-focus reduces the information update frequency. The pairing disorder caused by the IE6 bug will disrupt our plans.
I did not find any official instructions or recommended solutions for this bug on the Internet, so I had to develop a solution.
The Code is as follows:

The Code is as follows:




Hello
Script
(Function (){
Var focusTimer = 0;
Function myBlur (){
Document. title = 'blur: '+ Math. random ();
}
Function myFocus (){
ClearTimeout (focustout );
Focustout = setTimeout (function (){
Document. title = 'focus: '+ Math. random ();
}, 10 );
}
Window. onfocus = document. body. onfocusin = myFocus;
Window. onblur = document. body. onfocusout = myBlur;
}());
Script


The principle is: find many opportunities that may trigger onfocus and onblur. All onblur will be executed immediately, while onfocus will be executed with a delay of 10 milliseconds.
The result is: although the myFocus and myBlur are executed several times, the window status is correct.
The method may be a little shanzhai, but I didn't expect a better solution at the moment, which can solve the pressing problem for the moment.
Related Article

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.