Home >Web Front-end >JS Tutorial >How to close the browser with javascript
Javascript method to close the browser: 1. Close the browser web page through the "function CloseWebPage(){...}" method; 2. Use "open(location, '_self').close() ;" method closes the browser web page.
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
js realizes closing the browser
Compatible with all browser web page closing methods
<button id="exitSystem" onclick="CloseWebPage()">关闭</button> <script> function CloseWebPage() { if (navigator.userAgent.indexOf("MSIE") > 0) { if (navigator.userAgent.indexOf("MSIE 6.0") > 0) { window.opener = null; window.close(); } else { window.open('', '_top'); window.top.close(); } } else if (navigator.userAgent.indexOf("Firefox") > 0) { window.location.href = 'about:blank '; //火狐默认状态非window.open的页面window.close是无效的 //window.history.go(-2); } else { window.opener = null; window.open('', '_self', ''); window.close(); } } </script>
The two methods can also be used for Google Chrome’s
<button style="margin-left: 500px" onclick="CloseWebPage()">退出</button> <script> function CloseWebPage() { open(location, '_self').close(); } </script>
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to close the browser with javascript. For more information, please follow other related articles on the PHP Chinese website!