Prevent js alert() from pausing timers

后端 未结 8 850
花落未央
花落未央 2021-01-06 01:54

So I made some timers for a quiz. The thing is, I just realized when I put

javascript: alert(\"blah\");

in the address, the popup alert bo

8条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-06 02:00

    Apparently the preview rendering differs from the posted rendering. This paragraph is here to make sure the next two lines show up as code.

    // Preserve native alert() if you need it for something special
    window.nativeAlert = window.alert;
    
    window.alert = function(msg) {
        // Do something with msg here. I always write mine to console.log,
        // but then I have rarely found a use for a real modal dialog,
        // and most can be handled by the browser (like window.onbeforeunload).
    };
    

提交回复
热议问题