Home >Web Front-end >JS Tutorial >Interpret the execution order of JScript and HREF under IE and Firefox_javascript skills
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: ->d.htm ->d.htm
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
->b.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
e.htm
c.htm
->b.htme.htm
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.