Home > Web Front-end > JS Tutorial > How to close the browser with javascript

How to close the browser with javascript

藏色散人
Release: 2023-01-05 16:11:44
Original
10381 people have browsed it

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.

How to close the browser with javascript

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(&#39;&#39;, &#39;_top&#39;); window.top.close();
                    }
                }
                else if (navigator.userAgent.indexOf("Firefox") > 0) {
                    window.location.href = &#39;about:blank &#39;; //火狐默认状态非window.open的页面window.close是无效的
                    //window.history.go(-2);
                }
                else {
                    window.opener = null;
                    window.open(&#39;&#39;, &#39;_self&#39;, &#39;&#39;);
                    window.close();
                }
            }
        </script>
Copy after login

The two methods can also be used for Google Chrome’s

<button style="margin-left: 500px" onclick="CloseWebPage()">退出</button>
<script>
    function CloseWebPage() {
        open(location, &#39;_self&#39;).close();
    }
</script>
Copy after login

[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!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template