現在類似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){} }