Javascript警报与Jquery消息交替

时间:2013-02-05 08:47:33

标签: javascript jquery-ui jquery adblock

我只是一个学习者,并且没有关于javascript和jquery的线索。我想要广告拦截检测器脚本。我发现这段代码给出了一个令人讨厌的警报信息。我想要的是给出ajaxed消息,而不是从屏幕弹出的消息。

<script type="text/javascript">
function _enabled() {
    alert('Hey Dude!!! You are using Adblock on this site? Please disable Adblock or Any other plugin blocking ads. Its the only way we cover the cost of the Servers and Website. Click OK to continue what you were doing');
}
function _disabled() {
    alert('not detected');
}
var _abdDetectedFnc = '_enabled';
var _abdNotDetectedFnc = 'disabled';
</script>
<script type="text/javascript" src="http://www.adblockdetector.com/script.php"></script>

您可以替换此代码来替换此代码吗?

{
        alert('Hey Dude!!! You are using Adblock on this site? Please disable Adblock or Any other plugin blocking ads. Its the only way we cover the cost of the Servers and Website. Click OK to continue what you were doing');
    }

我找到了一些关于使用jquery或jquery-ui获取它的解决方案,但是不知道放在这里的内容并替换代码。我尝试了http://m0006.gamecopyworld.com/games/gcw_notice.shtml的代码示例,它提供了一个友好的Adblock Detect消息。但它根本不起作用。只有此警报消息在我的网站上正在运行。

4 个答案:

答案 0 :(得分:4)

作为一个非常快速的替代方案,你可以使用jQuery-ui对话框看起来更好一点(正如Ricky Baby所说)

您还需要在页面中包含jQuery和jQuery-ui库。 如果您还没有这些,可以从http://jquery.com/download/http://jqueryui.com/download/下载这些内容。

您可以将“Hey dude ...... etc”文本更改为您喜欢的内容

<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css" type="text/css" media="all" />
</head>
<body style='height: 100%;'>
<script type="text/javascript">
function _enabled() 
{
    var html = "<div>Adbloc detected</div>";

    var diag = $(html).dialog(
    {
        autoOpen: true,
        modal: true,
        close: function() { $(this).empty().remove(); },
        buttons: 
        {
            "Close": function() { $(this).dialog("close"); }
        }
    });
}
function _disabled() 
{
    var html = "<div>Adbloc NOT detected</div>";

    var diag = $(html).dialog(
    {
        autoOpen: true,
        modal: true,
        close: function() { $(this).empty().remove(); },
        buttons: 
        {
            "Close": function() { $(this).dialog("close"); }
        }
    });
}
var _abdDetectedFnc = '_enabled';
var _abdNotDetectedFnc = '_disabled';
</script>
<script type="text/javascript" src="http://www.adblockdetector.com/script.php"></script>
</body>
</html>

或者你可以在屏幕底部放一条消息,如果你根本不想弹出一个

<div id='adBlockDetected' style='position: fixed; bottom: 20px; left: 0px; width: 100%; display: none;' >Hey dide .... etc </div>

然后在_enabled()函数

$("#adBlockDetected").css({display: "block" });

答案 1 :(得分:2)

看到这个问题:

Problems with Adblock detecting

在底部,他通过设置html属性将消息设置为显示在div(他称之为#Ad-One)中。

答案 2 :(得分:1)

如果您想使用JQuery-ui,可以使用对话框选项使消息框更加美观,请参阅:http://jqueryui.com/dialog/

但是,您的条款也混淆了--AJAX--是使用XMLHTTP对象和相关技术从远程服务器请求数据的“品牌”名称。

答案 3 :(得分:0)

如果您只需要“漂亮”的警报,jQuery UI就有点过分了。我会选择像爱普瑞斯这样的东西:http://thrivingkings.com/read/Apprise-v2-The-new-and-improved-attractive-alert-alternative-for-jQuery

只使用默认设置:

<!-- added to head -->
<link href="path_to_css/apprise-v2.min.css" rel="stylesheet" type="text/css" />

<script src="path_to_jquery"></script>
<script src="path_to_scripts/apprise-v2.min.js"></script>
<script>

    $(function(){
        Apprise('hi there');
    });

</script>

为您提供一个非常灵活的提醒信息:

enter image description here

当然,我也很好奇你在这里想要达到的目标:

<script type="text/javascript" src="http://www.adblockdetector.com/script.php"></script>

除非PHP页面实际上是JavaScript文件,否则你不能这样做。 src属性需要指向有效且可寻址的JavaScript文件。