---
title: "window.close()不出现提示框的方法"
author: "wangyanlong0107"
date: "2015-12-02T15:15:23Z"
tags: []
categories: ["Web前端"]
slug: "window-close"
draft: false
lastmod: "2015-12-02T15:15:23Z"
id: 2261124
url: "https://bigdragon.iteye.com/blog/2261124"
---

当我们使用window.close()时经常会出现一个提示框，提示我们是否关闭。

我们可以用如下方法，来去除提示框从而增加客户体验。

 

Html代码  [![收藏代码](http://starfive.iteye.com/images/icon_star.png)]()

01. function Close(){
02. var ua = navigator.userAgent;
03. var ie = navigator.appName == "Microsoft Internet Explorer"?true:false;
04. if(ie){
05. var IEversion = parseFloat(ua.substring(ua.indexOf("MSIE")+5,ua.indexOf(";",ua.indexOf("MSIE"))));
06. alert(IEversion);
07. if(IEversion &lt; 5.5){
08. var str = "&lt;object id = 'noTipClose' classid='clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11'&gt;";
09. str += "&lt;param name='Command' value='Close'/&gt;&lt;/object&gt;";
10. document.body.insertAdjacentHTML("beforeEnd",str);
11. document.all.noTipClose.Click();
12. }else{
13. window.opener = null;
14. window.open('','\_self','');
15. window.close();
16. }
17. }else{
18. widow.close();
19. }
20. }