我如何自动关闭网页? [英] How do I automatically close a webpage?
问题描述
我需要设置网页上的计时器自动关闭。有人可以帮助我的JavaScript的?
此解决方案是行不通的:
< SCRIPT LANGUAGE =JavaScript的类型=文/ JavaScript的>
功能winClose(){
window.setTimeOut(window.close()的;,5000)
}
< / SCRIPT><身体的onload =winClose();>
您只想关闭当前窗口,超时(比如5秒)后,像这样:
的setTimeout(window.close()的,5000);
修改
这里是一个更复杂的例子中,使用上述的技术中,在那里测试细甚至在IE9
< HTML和GT;
< HEAD>
<脚本>
功能加载()
{
警报(哔!);
window.setTimeout(CloseMe,500);
}功能CloseMe()
{
window.close()的;
}
< / SCRIPT>
< /头>
<身体的onLoad =加载()>
你好!
< /身体GT;
编辑2
这不会在Firefox仅仅是因为工作,因为Mozilla的文档状态,的这种方法(window.close)只允许被要求使用window.open方法的脚本时打开的窗口...... 的
I need to set a timer on a webpage to automatically close it. Can someone help me with the JavaScript?
This solution is not working:
<script language="JavaScript" type="text/javascript">
function winClose() {
window.setTimeOut("window.close();",5000)
}
</script>
<body onload="winClose();">
You would just close the current window, after a timeout (say, 5 seconds), like so:
setTimeout("window.close()", 5000);
EDIT Here is a more elaborate example, using the technique above, which tests fine even in IE9:
<html>
<head>
<script>
function loaded()
{
alert("Beep!");
window.setTimeout(CloseMe, 500);
}
function CloseMe()
{
window.close();
}
</script>
</head>
<body onLoad="loaded()">
Hello!
</body>
EDIT 2 This will not work in Firefox simply because, as the Mozilla documentation states, "This method (window.close) is only allowed to be called for windows that were opened by a script using the window.open method..."
这篇关于我如何自动关闭网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!