4

For my website I would like an alert box message to appear 4 seconds after the page is opened. I cant figure out how to do this as the timed function works if a button is clicked but I would like the alert box to pop up automatically withoutt any user input/button and then shut when the user clicks "okay"...

Any ideas or posts related to this topic would be great help!

Thanks

4

3 回答 3

7
<script type = "text/javascript">
window.onload=function(){setTimeout(showPopup,4000)};

function showPopup()
{
   //write functionality for the code here
}
</script>
于 2013-05-30T12:25:42.183 回答
4

以最简单的形式:

setTimeout(function(){alert("Hello")},4000);

4000 = 4 秒

于 2013-05-30T12:25:45.647 回答
2

如果您希望在大约某个时间后出现警报,请使用以下代码:

setTimeout(function() { alert("Your Message"); }, time);
于 2013-05-30T12:26:28.037 回答