Is there any mechanism for window.location.href?

places
(function () {

window.location.href= "www.baidu.com"
alert("23")
console.log(123)

} ())
why does console pop up first? The same is true in ajax, window.location.href does not jump? Is there any mechanism for solving this?

Apr.11,2021

window.location.href does not block all code immediately, unlike alert , it waits for at least one page departure event, and at the same time, the code executes further.

alert blocks the current code. There's nothing to ask about this. That's the rule. Both alert,confirm and prompt are on Synchronize, so the rest of the code will be blocked.

The location.href in
ajax does not jump?

question is not clear, I checked similar keywords, this is what you want to say, Artical , it is not difficult to understand that the redirection of submit is before the success callback.

if this is not the case, I suggest you add the question


is asynchronous
because the LocationChange behavior is executed asynchronously from the timer in the browser kernel, and the code can be found in the Chromium source NavigationScheduler::ScheduleFrameNavigation. The advantage of asynchronous execution is to prevent the code from being called too deep, resulting in stack overflow, and also to prevent recursion from entering the loading logic, causing state disorder, and ensuring that navigation requests are executed sequentially.

answers on Zhihu

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b1c3-2c26f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b1c3-2c26f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?