These two events are common.
I understand the differences between the two events, but I didn't actually use the differences between the two events to perform some operations.
Generally, onmousedown can be used when onclick is used, and more can be used when onclick is used.
We hereby record the problem that onmousedown cannot be used today.
Differences: Onclick is an event triggered after the mouse clicks. Onmousedown is an event triggered after the mouse is pressed.
In short, onclick = onmousedown + onmouseup;
If you move the mouse away from another place, releasing the mouse will trigger the onmousedown event, but the onclick event will not be triggered.
The function we want to implement today is to click the tag and switch to another page. a function needs to be triggered before the previous page is closed. Not windowunload.
Previously, the onclick event was used, and the test in IE was normal. However, the test in FF found that the function had not been executed before the page was destroyed.
If the onmousedown event is used, although there is no way to ensure that the function will be executed, it takes some time to execute the function, because the jump is executed after the mouse pops up.
Solution 1: Onclick = "return test ()". The jump is executed only when the function returns true. This leads to a new problem. If we execute a multi-threaded program or a new program in the test function, true is returned first, and the new thread is not executed. The following functions:Copy codeThe Code is as follows: function test ()
{
(New Image (). src = "1.html ";
Window. open ("1.html", "_ new ");
// Alert ("OK ");
Return true;
}
In the 1.html file, I set <body onload = "javascript: alert ('OK')">. When 1.html is not completely rendered, the redirection has been executed. The new image function is not guaranteed to be executed.
Return test () can be used to execute functions in a single thread.
Solution 2: It is estimated that the maximum execution speed of the multi-threaded function of the test function is 100. Skip is not used in tag. Use setTimeout (location. href = "1.html", 100) in the test function to perform the jump.