javascript 定时提醒框弹出网站?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16836075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 06:11:05  来源:igfitidea点击:

Timed alert box pop up for website?

javascripthtmlcssalert

提问by BLS93

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"...

对于我的网站,我希望在页面打开 4 秒后出现警告框消息。我无法弄清楚如何做到这一点,因为如果单击按钮,定时功能会起作用,但我希望警报框在没有任何用户输入/按钮的情况下自动弹出,然后在用户单击“好的”时关闭...

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

与此主题相关的任何想法或帖子都会有很大帮助!

Thanks

谢谢

回答by Harsha Venkatram

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

function showPopup()
{
   //write functionality for the code here
}
</script>

回答by MaX

In it's most simple form:

最简单的形式:

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

4000 = 4 seconds

4000 = 4 秒

回答by rags

If you want an alert to appear after a certain about time use this code:

如果您希望在一段时间后出现警报,请使用以下代码:

setTimeout(function() { alert("Your Message"); }, time);