user2265863
user2265863

Reputation:

JavaScript: How To Make A Prompt Happen Later

This is a very basic question but how do you make a prompt appear later after the webpage has loaded? My code for the prompt looks like this:

<html>
    <body>
        <script type="text/javascript">
            window.prompt("Prompt Here!")
        </script>
    </body>
</html>

What can I use to make the file execute the prompt after a little while?

Upvotes: 0

Views: 267

Answers (2)

gdoron
gdoron

Reputation: 150263

document.body.onload = function(){
    window.prompt("Prompt Here!");
});

Or:

<body onload="window.prompt('Prompt Here!');">

Upvotes: 0

ryanbrill
ryanbrill

Reputation: 2011

You'd use a setTimeout().

setTimeout(function() {
    window.prompt("Prompt Here!");
}, 1000);

Upvotes: 2

Related Questions