I want to overload the standard alert behavior. This is done simply:

function alert(_m){ //code // ΠΏΡ€Π΅Π΄ΠΏΠΎΠ»ΠΎΠΆΠΈΠΌ здСсь я Ρ€ΠΈΡΡƒΡŽ окошко ΠΈΠ· div элСмСнтов ΠΈ ΠΎΠ΄Π½ΠΎΠΉ ΠΊΠ½ΠΎΠΏΠΊΠΎΠΉ, просто Π΄ΠΈΠ·Π°ΠΉΠ½ мСняю. } 

The question is how do I delay the execution of the function until my user performs the necessary actions in my window. The delay is not suitable, as this is the worst option.

I myself believe that there is a certain way to manage the script, and you can somehow pause it, and then continue from the breakpoint or another point.

PS: firebug somehow allows you to debug, then there is a mechanism ...

    2 answers 2

    First, Firebug is still not just a script, but an extension that has access to the platform API (for example, Mozilla). Therefore, he makes stops at the indicated points with the help of the engine. Secondly, browsers have such a thing as "UI thread" - this is a stream shared (in the sense of "shared") by UI events on the page and by the custom JS on the same page. This separation means that you cannot simultaneously execute the JS code and display a responsive page to the user. You can organize something similar and working (as is usually done) with setTimeout() / setInterval() , but in fact it is only a postponement for later - this is not the launch of a separate thread in the full sense of the word, it is rather a transfer of a part of the code to the β€œfuture” of the same UI thread.

    From the above, we can conclude that it is impossible to create a blocking function in the custom JS so that it works exactly as alert() . In the end, you will need something like an infinite loop to check for some condition that will take all the work of the UI thread. In doing so, you will not be able to use setInterval() , since then your alert() will not be blocking.

    Perhaps a mistake has crept into my thoughts, I will be glad to any objections.

    • I can not disagree, but for now I will refrain, because I am digging hard in this direction! I can only dream about the benefits of blocking functions!)) - org
    • I have been digging for a long time and hard, and now I fully agree with you: it is impossible. <img src = "/ vote / 31701 / up /" width = "1px" /> <img src = "/ vote / 30730 / up /" width = "1px" /> <img src = "/ vote / 22250 / up / "width =" 1px "/> <img src =" / vote / 19593 / up / "width =" 1px "/> - org
    • @org Yes, I have long known that it is impossible :) - Rules

    There is a stupid, but option - to register callback:

     function alert(x, c){ prompt(x); if(c) c(); } alert('test', function(){alert('stop');}); 

    And if you display the message with divs, you can hang the callback on the OK button.

    • This is a long time familiar way! By the way, sir, you are looping!) - org
    • I'm looping? Yes, this can not be). And what this method did not please? - ling
    • To put it mildly, not all programmers understand the flashpacks. It would be nice for them, and it would be more comfortable for professionals to program! - org