Javascript 超时后自动关闭窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12791695/
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
Automatically close window after timeout
提问by Max Gee
I know php is server-side, but is there a way to make this window close after 3 seconds?
我知道 php 是服务器端的,但是有没有办法让这个窗口在 3 秒后关闭?
<link rel="stylesheet" type="text/css" href="style1.css" />
<?php
$contact_message=$_POST['message'];
$errpage = $_POST['frompage'];
$ip=$_SERVER['REMOTE_ADDR'];
$message = "$contact_message -SENT FROM THIS IP: $ip";
mail("[email protected]", "$Error Reported on: $errpage", $message);
echo "We have documented the web address of the problem and thank you for helping us improve our site!"
?>
回答by Terence Johnson
This should do it:
这应该这样做:
<script type="text/javascript">setTimeout("window.close();", 3000);</script>
回答by GSGupta
It is very simple - just write the JavaScript code in PHP with echo in the place where you want to move out from itself, such as:
很简单——只需要在 PHP 中写出带有 echo 的 JavaScript 代码在你想从自身移出的地方,比如:
<?php
echo '<script> window.setTimeout("window.close()", 1000); </script>';
?>
It will definitely work.
它肯定会起作用。
回答by jiguang
It may seems a little weird if a page I am watching suddenly be closed.
如果我正在观看的页面突然关闭,这可能看起来有点奇怪。