javascript 打开后立即关闭窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7543161/
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
Close window as soon as it opens
提问by Hailwood
I am using the facebook dialog feed to allow the user to post a message to their wall.
我正在使用 facebook 对话框提要允许用户在他们的墙上发布消息。
You must provide a redirect_url for the page to redirect to after it has submitted, I want on the page it redirects to to have some code which simply closes the windows.
您必须为提交后的页面提供一个 redirect_url 以重定向到该页面,我希望在它重定向到的页面上有一些代码可以简单地关闭窗口。
I tried using
我尝试使用
<html><head><title>Close</title></head><body onload="window.close();"></body></html>
and<html><head><title>Close</title></head><body onload="self.close();"></body></html>
<html><head><title>Close</title></head><body onload="window.close();"></body></html>
和<html><head><title>Close</title></head><body onload="self.close();"></body></html>
but to no effect.
但没有效果。
(note that my testing is simply me opening a new tab with this url, could that be the issue?)
(请注意,我的测试只是我用这个 url 打开一个新标签,这可能是问题吗?)
回答by Rusty Fausak
You can only close windows with javascript if they were opened with javascript.
如果使用 javascript 打开窗口,则只能使用 javascript 关闭它们。
Otherwise, try looking at this question: How can I close a browser window without receiving the "Do you want to close this window" prompt?
否则,请尝试查看此问题:如何在不收到“您想关闭此窗口”提示的情况下关闭浏览器窗口?