javascript - When using location.href to jump to a page, it does not jump immediately?
怪我咯2017-06-28 09:28:41
0
3
1043
location.href="login.html"
I found that it does not jump immediately after executing this statement, but after all the JS statements following the statement are executed, the jump is performed. Why?
No, I tested it and it didn’t happen. It jumps immediately. You can post your code and see if it has anything to do with your code, such as whether it is in an asynchronous function
The assignment of
window.location.href
will not interrupt the execution of Javascript. So it’s best to add a statement likereturn
at the end to end itIf you need to jump directly without executing the following, you can add return false;
after the jumpNo, I tested it and it didn’t happen. It jumps immediately. You can post your code and see if it has anything to do with your code, such as whether it is in an asynchronous function