javascript 等待弹出窗口javascript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14747298/
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
Wait popup window javascript
提问by abierto
Basically I'm doing this:
基本上我这样做:
window.onload=function wait(){
alert ("Please, wait until process has finished.");
window.location="index.jsp";
};
What I need is, an alert window, or something similar that will disappear/enable the "OK" button in the popup window, only after X seconds are passed.
我需要的是一个警报窗口或类似的东西,它会在弹出窗口中消失/启用“确定”按钮,只有在 X 秒过去后。
How can I do this?
我怎样才能做到这一点?
回答by Teemu
Maybe you need something like this:
也许你需要这样的东西:
window.onload = function () {
var popup = window.open('','pop','width=200px, height=10px'),
popdoc, msg, script;
if (popup) {
popdoc = popup.document;
msg = popdoc.body.appendChild(popdoc.createElement('p'));
msg.innerHTML = 'Please, wait until process has finished.';
script = popdoc.createElement('script');
script.text = '(function () {setTimeout(function () {self.close();}, 3000);}());';
popdoc.body.appendChild(script);
}
}
A demo at jsFiddle
jsFiddle的演示
回答by Kolby
var wait = function() {
alert ("Please, wait until process has finished.");
}
setTimeout(wait, 3000);
The 3000 is the miliseconds you want to wait before it calls the function.
3000 是在调用函数之前要等待的毫秒数。
回答by themightysapien
just pass the function to the the settimeout
只需将函数传递给 settimeout
setTimeout(yourfunction,2000);
this will run the function after 2 sec of the doc load
这将在文档加载 2 秒后运行该函数