在JavaScript中关闭窗口

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在JavaScript中关闭窗口相关的知识,希望对你有一定的参考价值。

The function that closes window is very useful when you use a pop-up window on your page, because it allows the visitor to easily close the window. You can also do it several ways: to use a button, a text link or make the window closes automatically after a given number of seconds.
  1. <!-- Sample #1: form button -->
  2. <form>
  3. <input type=button value="Close This Window" onclick="javascript:window.close();">
  4. </form>
  5.  
  6. <!-- Sample #2: text link -->
  7. <a href="javascript:window.close();">Click Here to Close Window</a>
  8.  
  9. <!-- Sample #3: close window after a given number of seconds -->
  10. <body onload="setTimeout(window.close, 10000)">...</body>

以上是关于在JavaScript中关闭窗口的主要内容,如果未能解决你的问题,请参考以下文章

如何阻止用户在 Javascript 中关闭窗口?

JavaScript 在Firefox和Internet Explorer中关闭窗口

应用程序在主要活动中关闭onBackPressed

如何在导航控件片段中关闭导航 DrawerLayout onBackPressed

目标窗口在硒中关闭

JS中关闭弹窗的问题