简体   繁体   English

JS window.close不起作用

[英]JS window.close doesnt work

Code snippet to make make popup window: 制作make弹出窗口的代码片段:

<script>
function about() {
window.open( "/aboutserver.html", "_blank", 
"location=no, titlebar=no, status = no, height = 650, width = 300, resizable = no, location=no, menubar=no, scrollbars=no, toolbar=no");
}
</script>
<a href="#" onClick="about()">Server Info</a> <br>

Here is the code of the actual popup window: 这是实际弹出窗口的代码:

<div align="center"><html><body><h1>Info</h1></div>
<br>Provides:<br><br><br>
blah blah etc
<script>
function close(){
window.self.close();
}
</script>
<button onClick=close()>Close</button>

I have also tried window.close(); 我也尝试过window.close(); and window.close('aboutserver.html') 和window.close('aboutserver.html')

You're overriding the global close function. 您将覆盖全局close功能。 You should be getting a stack overflow error from the function trying to call itself. 您应该从试图调用自身的函数中收到堆栈溢出错误。

You can just remove your custom close function and just call the global close() directly, or rename your function to something like closeWin 您可以删除自定义close函数并直接调用全局close() ,或将函数重命名为closeWin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM