最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to run script behind alert box in javascript? - Stack Overflow

programmeradmin2浏览0评论

I want to run alert("hi") in 3 seconds after alert("hello") without clicking on OK of "hello" alert.

This is my code:

$(function(){
    alert("hello");
    setTimeout(function(){
        alert("hi");
    },3000)
})

I want to run alert("hi") in 3 seconds after alert("hello") without clicking on OK of "hello" alert.

This is my code:

$(function(){
    alert("hello");
    setTimeout(function(){
        alert("hi");
    },3000)
})
Share Improve this question edited Jan 29, 2015 at 9:11 Nikolay Kostov 17k23 gold badges89 silver badges129 bronze badges asked Jan 29, 2015 at 8:54 Akshay JainAkshay Jain 514 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

If you read the doc you will understand that is not possible:

Notes

The alert dialog should be used for messages which do not require any response on the part of the user, other than the acknowledgement of the message.

Dialog boxes are modal windows - they prevent the user from accessing the rest of the program's interface until the dialog box is closed. For this reason, you should not overuse any function that creates a dialog box (or modal window).

Chrome users (e.g. extensions) should use methods of nsIPromptService instead.

When alert alerts, it blocks the UI as well as the thread. do that. The next line of code runs after the alert has been dismissed.

So, there's no way to do that. You can use Twitter's Bootstrap's modals, may be. (There are many others too, like Foundation, jQuery UI that gives you the ability to have a modals)

发布评论

评论列表(0)

  1. 暂无评论