Interpreting the execution sequence of JScript and HREF in IE and firefox _ javascript skills

Source: Internet
Author: User
The execution sequence of JScript and HREF in IE and firefox has not been written about the code for a long time. The main reason is that the recent work has been concentrated on demand analysis. without the feeling in reality, there is no motivation for writing. A question about the execution sequence of JScript is discussed. The sample code is as follows:
A.htm
Click Me! Click Me!
SCRIPT
Function func (str)
{
Msg (str );
Window. location. href = "c.htm ";
}
Function msg (str)
{
Document. getElementById ("msg"). innerText = str; //
// Alert (str); // B
}
Function func2 (str)
{
Msg (str );
Window. location. href = "e.htm ";
}
SCRIPT
In msg (str), there is A comment-out line. during the test, A and B are executed respectively.

A B
Onmouseup Onclick Onmouseup Onclick
IE B .htm D.htm C.htm D.htm
FireFox C.htm-> B .htm E.htm-> d.htm C.htm-> B .htm E.htm-> d.htm

The preceding table lists the execution sequence of the two browsers. red indicates the page to jump to by page script, and blue indicates the href attribute of the Anchor tag. From the above we can see that for FireFox, the page script is always executed first, and then the browser jumps. The execution process in IE is different:
1. Use the back-to-back button to directly return to a.htm, that is, only one jump is performed on the page;
2. when alert is interrupted, onmouseup executes the redirection in the page script.

As shown in the preceding figure,
1. for FireFox, the page script execution sequence always takes precedence over the embedded script execution sequence in the browser, which is already obvious.
2. in IE, the sequence of HREF execution is onmouseup-> href-> onclick. Really?

To clarify the execution sequence in step 2, we continue to analyze the execution sequence relationship between onclick and href. In the preceding example, onclick is executed by calling. If a. We use the following test code:
Click Me!
FoundHREF cannot be executed.
B. If we use the following test code:
Click Me!
Still foundExecute the d.htmfor href, instead of the e.htm in onclick.
C. If we use the following test code:
Click Me! (Function msg () code above)
FoundFunction msg () is executed, while HREF is not triggered.

Dizzy. IE is indeed a strange thing. Who can help explain the phenomenon in Example B?

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.