Why not pause after alert, but immediately refresh the address, this alert is written by yourself?

Feb.26,2021

enter alert in the console without parentheses to see the original code and only see native code


do you test with the console open? you have just tested it with chrome. If the console is open and the console is in focus, alert will not immediately block the running thread, but will not issue alert and block the thread until the focus returns to the page from the console. However, if you modify window.location.href immediately after executing window.location.href , and the console gets focus again, alert will not block the thread immediately, and jvm will execute the next statement to modify window.location.href , which will result in the cancellation of alert that has not been issued before (I guess).

the conclusion is that do not test this code with the console open.

here is my test code:

setTimeout(() => $.ajax({
    url: '/',
    type: 'GET',
    success: data => {
        console.log('Before rua');
        alert('Rua!');
        console.log('After rua');
        window.location.href += '-sharp';
    },
    error: (...args) => console.log(...args)
}), 1000);

if you do not switch focus back to the page within 1 second, alert will not be issued, and window.location.href will be modified immediately; if you switch focus back to the page within 1 second, alert will be issued, and window.location.href will be modified after you drop alert dismiss.

or more simply and rudely:

setTimeout(() => {
    console.log('Before rua');
    alert('Rua!');
    console.log('After rua');
    window.location.href += '-sharp';
}, 1000);

same as above, you can see alert when you switch back to the page within 1 second. After dismiss, window.location.href will be modified, otherwise alert will be cancelled.

comparison with the above code:

setTimeout(() => {
    console.log('Before rua');
    alert('Rua!');
    console.log('After rua');
    // window.location.href += '-sharp';
}, 1000);

just send out a alert without modifying window.location.href . After entering the above code and running it in the console, wait a second to see the console output "Before rua" and "After rua", and then switch the focus back to the page, you will see a alert pop-up.

to sum up, I guess alert can also be asynchronous-when the rendering process detects that the current page does not get focus, such as minimized by the user, if the js embedded in the page tries to issue alert , the rendering process will not immediately pop up alert , but will put the request in a queue and wait for the next focus to pop up again.

add that the result of the current chrome test is that alert is issued when the focus is obtained by the console, and the window.location.href is modified after alert (the focus is still on the console). The alert will be cancelled directly. If you minimize the browser, the browser will automatically pop up and issue alert .


you can implement an alert, by yourself. After clicking OK, perform a jump operation


alert to stop the current operation. After confirmation, the following statement will be executed

Menu