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

我在使用MSN Webmessenger时,发现它可以告诉我使用了弹出窗口阻挡功能,在分析代码后,提取出下面的程序,可以直接使用。

<!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>

 

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/vince6799/article/details/815510
个人分类: JavaScript
想对作者说点什么? 我来说一句

不被浏览器拦截的JS弹出窗口

2011年06月15日 6KB 下载

没有更多推荐了,返回首页

不良信息举报

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

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭