Firefoxfocus creates a focus event for Firefox

Source: Internet
Author: User

As we all know, except for the tab line, the element in Firefox does not have the focus concept (you can add the tabindex attribute to the general element to make it focus ). no. Why not do it yourself.
<SCRIPT>
// Just can be running in Firefox Studio
If (document. addeventlistener)
Document. addeventlistener ("click", function (event) {firefoxfocuschange (event) ;}, false );
// The IE Brower does not support the Function
VaR lastfocus = new object; // get a object to pass the script interpreter
VaR currentfocus = NULL; // set the focus for other methods
Function firefoxfocuschange (e ){
VaR E = E | window. event; // compatibility, can be removed, because not to be running in IE Studio
VaR newfocuscmde.tar GET | E. srcelement; // Ditto
If (lastfocus! = Newfocus) {// console. Log ("focuschange ");
If (! Lastfocus. tabindex) {// console. Log ("notabindex"); // check element has property for tabindex to prevent running twice.
If (lastfocus. onblur) {// console. Log ("runblur ");
Lastfocus. onblur ();
}
}
}
If (currentfocus ){
Lastfocus = currentfocus; currentfocus = NULL;} // tested. In ff, the listener event occurs after the onclick method is executed. If the onclick method is used to change the focus, you must add currentfocus to this problem.
Else {
Lastfocus = newfocus ;}
}
</SCRIPT>

The test has passed and the comments are directly written in English. When I practice English and add this self-made script, I can directly fix the onblur problem in Firefox (you can also add the focus event ), in some old projects that can be used, I will encapsulate it and turn it into a module. An onfocus should be exposed (for advanced languages, it is equivalent to inheriting and overwriting ), stop the previous focus setting method on the chained search, so that he will not be allowed to go to the window. onfocus, so that onfocus is normal, do not know whether to give it, so that Firefox is exactly the same as the focus event in IE.

Firefoxfocus creates a focus event for Firefox

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.