Home  >  Article  >  Web Front-end  >  Interpret the execution order of JScript and HREF under IE and Firefox_javascript skills

Interpret the execution order of JScript and HREF under IE and Firefox_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:06:461085browse

I haven’t written an article about coding for a long time. The main reason is that recent work has focused on demand analysis. Without real-life feelings, there will be no motivation for writing. Discuss an issue about JScript execution order. The sample code is as follows:
a.htm
Click Me! < ;A onclick="func2('onclick')" href="d.htm">Click Me!
<SCRIPT><br>function func(str)<br>{<br> msg(str);<br> window.location.href="c.htm";<br>}<br>function msg(str)<br>{<br> document.getElementById("msg").innerText=str; //A<br> //alert(str); msg(str);<br> window.location.href="e.htm";<br>}<br></SCRIPT>


There is a comment in msg(str) Lines, execute A and B respectively during the test.

A B
onmouseup onclick onmouseup onclick
IE b.htm
d.htm c.htm d.htm

FireFox c.htm
   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 
->b.htm
e.htm

->d.htm

c.htm
->b.htm
e.htm

->d.htm


The above table mainly lists the execution order in the two browsers. Red represents the page to which the page script jumps, and blue is the href attribute of the Anchor tag. As can be seen from the above, 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 button to return directly to a.htm, that is, the page only performs one jump;
2. When using alert to interrupt, onmouseup is executed. Jumps in page scripts. As can be seen from the above,
1. For FireFox, the page script execution order always takes precedence over the browser embedded script execution order. This is already obvious. 2. In IE, the execution order of HREF is onmouseup->href->onclick. Really?
In order to make the execution order in 2 more clear, we continue to analyze the execution order relationship between onclick and href. In the above example, onclick is executed by calling. If a. We use the following test code:
Click Me!
Discover HREF cannot be executed.
b. If we use the following test code:
Click Me!
I found that the d.htm of HREF is still executed, instead of the e.htm in onclick.

c. If we use the following test code:

Click Me! (The code of function msg() is as above) found that executed function msg(), but HREF was not triggered. Dizzy. IE is indeed a weird thing. Who can help explain the phenomenon in case b?
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn