检测浏览器是否自动屏蔽了弹出窗口

 

现在类似Google Toolbar的工具条几乎都提供了弹出窗口阻挡的功能,但是在实际WEB开发工作中许多情况下还是需要自动谈出窗口,因此需要检测并提醒用户禁用该功能。

在使用MSN Webmessenger时,发现它可以告诉我使用了弹出窗口阻挡功能,在分析它的代码后,提取出下面的程序,可以直接在自己的项目中使用,经过检验,确实可以检测到IE中google等工具条的阻挡情况,但是GoSurf等多线程浏览器的阻挡弹出页面阻挡却没有检测出来,我将使用多种浏览器做一个测试,将结果加上来。

 

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > < HTML >< HEAD >< TITLE > 弹出窗口检查 </ TITLE > < META  http-equiv =Content-Type  content ="text/html; charset=utf-8" >
< SCRIPT language = javascript > function  openwindow(u,n,w,h) {      var  optionstring  =   " height= "   +  h  +   " ,width= "   +  w  +   " ,menubar=no,titlebar=yes,resizable=yes,scrollbars=no,status=no,toolbar=no " ;                             window.open(u,n,optionstring); } var     spbw  =   false ; function  ShowBlockerWarning() {      return  spbw; } function  Init() {      if  ( true   ==  Detect())     {         spbw  =   true ;     } } function  Detect() {      var  e  =   false ;      var  pw1  =   null ;      var  pw2  =   null ;      try     {          do         {              var  d  =   new  Date();              var  wName  =   " ptest_ "   +  d.getTime();              var  testUrl  =  IsYBI()  ?   " popupTest.aspx "  :  "" ;             pw1  =  window.open(testUrl,wName, " width=0,height=0,left=5000,top=5000 " , true );              if  ( null   ==  pw1  ||   true   ==  pw1.closed)             {                 e  =   true ;                  break ;             }             pw2  =  window.open(testUrl,wName, " width=0,height=0 " );              if  ( null   ==  pw2  ||   true   ==  pw2.closed)             {                 e  =   true ;                  break ;             }              if  (IsYBI())             {                  if  (pw1  !=  pw2)                 {                     e  =   true ;                      break ;                 }             }             pw1.close();             pw2.close();             pw1  =  pw2  =   null ;         }          while ( false );     }      catch (ex)     {         e  =   true ;     }      if  ( null   !=  pw1)     {          try  {  if  ( ! pw1.closed) pw1.close(); }  catch (ex){}     }      if  ( null   !=  pw2)     {          try  {  if  ( ! pw2.closed) pw2.close(); }  catch (ex){}     }      return  e; } function  IsYBI() {      var  i  =   false ;      try     {          var  xObj  =   new  ActiveXObject( " YBIOCtrl.CompanionBHO " );          if  (xObj == null ) i  =   false ;          else  i  =   true ;     }      catch (ex) { i  =   false ; }      return  i; } Init(); </ SCRIPT > < SCRIPT language = javascript > var  warningMessage  =   " 检查到使用了弹出窗口阻挡器!Pop-up blocker detected. " ; var  warningInformation  =   " 请确保浏览器允许本网站打开弹出窗口。 " ; var  g_blockerHtml; g_blockerHtml   =   " <div><table border=1 cellspacing=0 cellpadding=0> " ; g_blockerHtml  +=   " <tr><td> "   +  warningMessage  +   " </td></tr> " ; g_blockerHtml  +=   " <tr><td> "   +  warningInformation  +   " </td></tr> " ; g_blockerHtml  +=   " </table></div> " ; </ SCRIPT > < SCRIPT language = javascript > var  messengerWindow  =   null ; function  OnLoad_WelcomePage() {          if  ( ShowBlockerWarning() )         {              var  messageObject  =  document.getElementById( " noPopHtml " );              if  ( null   !=  messageObject)             {                 messageObject.innerHTML  =  g_blockerHtml;             }         } } </ SCRIPT >
</ HEAD > < BODY  onload =OnLoad_WelcomePage();> <SPAN  id =noPopHtml> </BODY > </ HTML >

上面的没有测试过

下面自己写的:

  1. <script language="javascript">   
  2.   
  3.         //    检测   
  4.   
  5.         var openWin = window.open("Login.aspx","信息系统","location=no,resizable=yes,status=yes,menubar=no,center=yes,scrollbars=no,left=0,top=0");   
  6.   
  7.         if ( openWin != null )   
  8.   
  9.         {   
  10.   
  11.             openWin .resizeTo(screen.availWidth,screen.availHeight);   
  12.   
  13.             window.opener = 'X';   
  14.   
  15.             window.open('','_parent','');   
  16.   
  17.             window.close();   
  18.   
  19.   
  20.   
  21.         }   
  22.   
  23.         else  
  24.   
  25.         {   
  26.   
  27.             alert('对不起,请关闭阻止弹出窗口程序,或者将本网站加入到受信任站点!');   
  28.   
  29. //            var host = top.location.host;   
  30.   
  31. //            var path = top.location.pathname;   
  32.   
  33. //            path = path.substr(1,path.length);   
  34.   
  35. //            path = path.substr(0,path.indexOf('/'));   
  36.   
  37. //            var url = 'http://' + host + '/' + path + '/Default/LogOut.aspx';   
  38.   
  39. //            top.location.href=url;   
  40.   
  41.         }   
  42.   
  43. //        if ( top.window.name != "信息系统" )   
  44.   
  45. //        {   
  46.   
  47. //            window.opener = 'X';   
  48.   
  49. //            window.open('','_parent','');   
  50.   
  51. //            window.close();   
  52.   
  53. //        }   
  54.   
  55.     </script>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
不同浏览器的无响应弹窗的时间设置方式可能会略有不同。以下是几种常见浏览器的设置方法: - Chrome浏览器:打开Chrome浏览器,在地址栏中输入 "chrome://settings/" 进入设置页面,然后点击左侧菜单栏的 "高级" 选项,再点击 "重置和清理" 下的 "清理计算机",最后在弹出的对话框中勾选 "计算机无响应时显示提示",并设置相应的时间间隔。 - Firefox浏览器:打开Firefox浏览器,在地址栏中输入 "about:config" 进入配置页面,然后搜索 "dom.max_script_run_time",双击该选项进行修改,单位是毫秒。默认值为0,表示不限制时间。可以将其设置为一个较大的值,比如1000,表示1秒钟。如果你想要改变弹窗的时间间隔,可以搜索 "dom.max_chrome_script_run_time",进行类似的设置。 - Edge浏览器:打开Edge浏览器,在地址栏中输入 "edge://settings/system" 进入系统设置页面,然后找到 "启用弹出窗口阻止程序" 的选项,打开该选项,然后点击 "详细信息",在弹出的对话框中找到 "计算机无响应时弹出提示" 的选项,设置相应的时间间隔。 - Safari浏览器:打开Safari浏览器,在菜单栏中选择 "Safari" -> "偏好设置" -> "高级",然后勾选 "在出现无响应时停止插件" 选项,设置相应的时间间隔。 需要注意的是,修改这些设置可能会影响浏览器的性能和稳定性,建议谨慎设置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值