js實現關閉瀏覽器


兼容所有瀏覽器網頁關閉方法

  

 1 <button  id="exitSystem" onclick="CloseWebPage()">關閉</button>
 2         <script>
 3             function CloseWebPage() {
 4                 if (navigator.userAgent.indexOf("MSIE") > 0) {
 5                     if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {
 6                         window.opener = null; window.close();
 7                     }
 8                     else {
 9                         window.open('', '_top'); window.top.close();
10                     }
11                 }
12                 else if (navigator.userAgent.indexOf("Firefox") > 0) {
13                     window.location.href = 'about:blank '; //火狐默認狀態非window.open的頁面window.close是無效的
14                     //window.history.go(-2);
15                 }
16                 else {
17                     window.opener = null;
18                     window.open('', '_self', '');
19                     window.close();
20                 }
21             }
22         </script>

 

 

第二種方法,也可以針對谷歌瀏覽器的

1 <button style="margin-left: 500px" onclick="CloseWebPage()">退出</button>
2 <script>
3     function CloseWebPage() {
4         open(location, '_self').close();
5     }
6 </script>

 

 

以上兩種方法,親測有效!!!!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM