Is there a JavaScript alert that doesn't pause the script?

后端 未结 6 1106
甜味超标
甜味超标 2020-11-28 07:51

I\'m looking for something like alert(), but that doesn\'t \"pause\" the script.

I want to display an alert and allow the next command, a form sub

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 08:13

    You could do the alert in a setTimeout (which a very short timeout) as setTimeout is asynchronous:

    setTimeout("alert('hello world');", 1);
    

    Or to do it properly you really show use a method rather than a string into your setTimeout:

    setTimeout(function() { alert('hello world'); }, 1);
    

    Otherwise you open yourself up to JavaScript injection attacks. When you pass a string it is run through the JavaScript eval function.

提交回复
热议问题