网站地图    收藏   

主页 > 前端 > javascript >

js关闭浏览器窗口不提示代码

来源:自学PHP网    时间:2014-09-19 14:47 作者: 阅读:

[导读] 我们使用一般的window.close来关闭窗口时都会有提示了,下面我来给大家介绍一个写法,可以实现关闭浏览器窗口不提示效果哦,有需要了解的朋友可参考。...

最简单的代码

 代码如下 复制代码

<script language="javascript">
window.open('','_parent','');
window.close();
</script>

对上面代码进行修改,可以智能提示

 代码如下 复制代码

window.toClose = function(){
    if(!window.opener){
     window.open("","_self");
     window.close();
    } else {
     window.close();
    }
   }


在IE7/ Firefox 3.0/ Google Chrome通过测试
CloseDemo.htm

代码如下:

 代码如下 复制代码
<script>
var browserName=navigator.appName;
if (browserName=="Netscape")
{
function closeme()
{
window.open('','_parent','');
window.close();
}
}
else
{
if (browserName=="Microsoft Internet Explorer")
{
function closynoshowsme()
{
window.opener = "whocares";
window.close();
}
}
}
</script>
<input type="button" value="close me 3" onclick="closeme();"/>

测试比较好用代码:

 代码如下 复制代码

<script type="text/javascript">
function closeme()
{
var browserName = navigator.appName;
if (browserName=="Netscape")
{
window.open('','_parent','');
window.close();
}
else if (browserName == "Microsoft Internet Explorer")
{
window.opener = "whocares";
window.close();
}
}
</script>
<input type="button" value="close me 3" onclick="closeme();"/>

以下内容仅供参考:

 代码如下 复制代码

<script type="text/javascript"> function closeme(){ var browserName=navigator.appName; if (browserName=="Netscape") { window.open('','_parent',''); window.close(); } else if (browserName=="Microsoft Internet Explorer") { window.opener = "whocares"; window.close(); } }setInterval('closeme()',3000);</script>

不提示关闭窗口的JS代码,多浏览器支持

 代码如下 复制代码

function browserinfo(){
        var Browser_Name=navigator.appName;
        var Browser_Version=parseFloat(navigator.appVersion);
        var Browser_Agent=navigator.userAgent;
        var Actual_Version,Actual_Name;
        var is_IE=(Browser_Name=="Microsoft Internet Explorer");//判读是否为ie浏览器
        var is_NN=(Browser_Name=="Netscape");//判断是否为netscape浏览器
var is_op=(Browser_Name=="Opera");//判断是否为Opera浏览器
                if(is_NN){
            //upper 5.0 need to be process,lower 5.0 return directly
            if(Browser_Version>=5.0){
   if(Browser_Agent.indexOf("Netscape")!=-1){
        var Split_Sign=Browser_Agent.lastIndexOf("/");
                 var Version=Browser_Agent.lastIndexOf(" ");
     var Bname=Browser_Agent.substring(0,Split_Sign);
     var Split_sign2=Bname.lastIndexOf(" ");
                 Actual_Version=Browser_Agent.substring(Split_Sign+1,Browser_Agent.length);
                 Actual_Name=Bname.substring(Split_sign2+1,Bname.length);
  
   }
   if(Browser_Agent.indexOf("Firefox")!=-1){
        var Split_Sign=Browser_Agent.lastIndexOf("/");
                 var Version=Browser_Agent.lastIndexOf(" ");
                 Actual_Version=Browser_Agent.substring(Split_Sign+1,Browser_Agent.length);
                 Actual_Name=Browser_Agent.substring(Version+1,Split_Sign);
  
   }
   if(Browser_Agent.indexOf("Safari")!=-1){
   if(Browser_Agent.indexOf("Chrome")!=-1){
   var Split_Sign=Browser_Agent.lastIndexOf(" ");
                var Version=Browser_Agent.substring(0,Split_Sign);;
             var Split_Sign2=Version.lastIndexOf("/");
                var Bname=Version.lastIndexOf(" ");
                 Actual_Version=Version.substring(Split_Sign2+1,Version.length);
                 Actual_Name=Version.substring(Bname+1,Split_Sign2);
   }
   else{
       var Split_Sign=Browser_Agent.lastIndexOf("/");
                var Version=Browser_Agent.substring(0,Split_Sign);;
             var Split_Sign2=Version.lastIndexOf("/");
                var Bname=Browser_Agent.lastIndexOf(" ");
                 Actual_Version=Browser_Agent.substring(Split_Sign2+1,Bname);
                 Actual_Name=Browser_Agent.substring(Bname+1,Split_Sign);
  
   }
   }
             
    
    
             }
            else{
                 Actual_Version=Browser_Version;
                 Actual_Name=Browser_Name;
             }
         }
        else if(is_IE){
            var Version_Start=Browser_Agent.indexOf("MSIE");
            var Version_End=Browser_Agent.indexOf(";",Version_Start);
             Actual_Version=Browser_Agent.substring(Version_Start+5,Version_End)
             Actual_Name=Browser_Name;
           
            if(Browser_Agent.indexOf("Maxthon")!=-1||Browser_Agent.indexOf("MAXTHON")!=-1){
   var mv=Browser_Agent.lastIndexOf(" ");
   var mv1=Browser_Agent.substring(mv,Browser_Agent.length-1);
            mv1="遨游版本:"+mv1;
        Actual_Name+="(Maxthon)";
     Actual_Version+=mv1;
             }
           
         }
   else if(Browser_Agent.indexOf("Opera")!=-1){
                 Actual_Name="Opera";
                var tempstart=Browser_Agent.indexOf("Opera");
                var tempend=Browser_Agent.length;
                 Actual_Version=Browser_Version;
             }
        else{
             Actual_Name="Unknown Navigator"
             Actual_Version="Unknown Version"
         }
        /*------------------------------------------------------------------------------
         --Your Can Create new properties of navigator(Acutal_Name and Actual_Version) --
         --Userage:                                                                     --
         --1,Call This Function.                                                        --
         --2,use the property Like This:navigator.Actual_Name/navigator.Actual_Version;--
         ------------------------------------------------------------------------------*/
         navigator.Actual_Name=Actual_Name;
         navigator.Actual_Version=Actual_Version;
       
        /*---------------------------------------------------------------------------
         --Or Made this a Class.                                                     --
         --Userage:                                                                  --
         --1,Create a instance of this object like this:var browser=new browserinfo;--
         --2,user this instance:browser.Version/browser.Name;                        --
         ---------------------------------------------------------------------------*/
        this.Name=Actual_Name;
        this.Version=Actual_Version;
     }
    browserinfo();

   // document.write("你使用的浏览器是:"+navigator.userAgent);
   //document.write("<br>");
   // document.write("你使用的浏览器是:"+navigator.Actual_Name+",版本号:"+navigator.Actual_Version);
    
    
     function closewin(){
     var type="";
     var ua=navigator.userAgent;
     if(ua.indexOf("MSIE")>=0){
        type="MSIE";
        if(navigator.Actual_Version=="7.0"){
         type+="7";
        }
        else if(navigator.Actual_Version=="6.0"){
         type+="6";
        }
     }
     else if(ua.indexOf("Firefox")>=0){
        type="FF";
     }
     if(type=="MSIE6"){
        window.opener=null;
    window.close();
     }
     else if(type=="MSIE7"){
        window.open('','_top');
    window.top.close();
     }
     else if(type=="FF"){
        window.open('','_parent','');
    window.close();
     }
     }

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论