如何在 PHP 中关闭当前窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16585886/
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
how to close current window in PHP
提问by rahul singh
I want to take a value in session then close the current window.
我想在会话中取一个值然后关闭当前窗口。
if(isset($_POST['ok']))
{
echo "<script type='text/javascript'>";
echo "closeCurrentWindow()";
echo "</script>";;
}
Why isn't this working?
为什么这不起作用?
回答by Nishant Kaushal
if(isset($_POST['ok']))
{
echo "<script type='text/javascript'>";
echo "window.close();";
echo "</script>";
}
回答by Wander Nauta
Do you define closeCurrentWindow() somewhere? You can't just make up functions and expect them to work :)
你在某处定义了 closeCurrentWindow() 吗?您不能只是编写函数并期望它们起作用:)
Try window.close()
. Be aware of its limitations though:
试试window.close()
。但请注意其局限性:
The close method closes only windows opened by JavaScript using the open method. If you attempt to close any other window, a confirm message is displayed, asking the user to choose whether the window is to be closed or not.
close 方法仅关闭由 JavaScript 使用 open 方法打开的窗口。如果您尝试关闭任何其他窗口,则会显示一条确认消息,要求用户选择是否关闭该窗口。
Source: http://www.javascript-coder.com/window-popup/javascript-window-close.phtml
来源:http: //www.javascript-coder.com/window-popup/javascript-window-close.phtml
回答by Matheno
<script>
function openWin()
{
myWindow=window.open("","","width=200,height=100");
myWindow.document.write("<p>This is 'myWindow'</p>");
}
function closeWin()
{
myWindow.close();
}
</script>