javascript - 广告 block 加上阻止 jQuery 脚本?

标签 javascript jquery adblock

我有一个脚本可以从我的 CMS 中提取数据,然后允许一个人在民意调查中投票。该脚本工作正常。但是,我在 Firefox 中安装了 Ad Block Plus Plugin。启用后会阻止脚本正确提交表单。它似乎在前端正确提交,但从未在后端注册。

为什么 Ad Block Plus 会屏蔽我的与广告无关的脚本?

脚本如下:

$(document).ready(function () {

    var Engine = {
        ui: {
            buildChart: function() {

                if ($("#pieChart").size() === 0) {
                    return;
                }

                var pieChartData = [],
                    totalVotes = 0,
                    $dataItems = $("ul.key li");

                // grab total votes
                $dataItems.each(function (index, item) {
                    totalVotes += parseInt($(item).data('votes'));
                });

                // iterate through items to draw pie chart
                // and populate % in dom
                $dataItems.each(function (index, item) {
                    var votes = parseInt($(item).data('votes')),
                        votePercentage = votes / totalVotes * 100,
                        roundedPrecentage = Math.round(votePercentage * 10) / 10;

                    $(this).find(".vote-percentage").text(roundedPrecentage);

                    pieChartData.push({
                        value: roundedPrecentage,
                        color: $(item).data('color')
                    });
                });

                var ctx = $("#pieChart").get(0).getContext("2d");
                var myNewChart = new Chart(ctx).Pie(pieChartData, {});

            }, // buildChart

            pollSubmit: function() {

                if ($("#pollAnswers").size() === 0) {
                    return;
                }

                var $form = $("#pollAnswers"),
                    $radioOptions = $form.find("input[type='radio']"),
                    $existingDataWrapper = $(".web-app-item-data"),
                    $webAppItemName = $existingDataWrapper.data("item-name"),
                    $formButton = $form.find("button"),
                    bcField_1 = "CAT_Custom_1",
                    bcField_2 = "CAT_Custom_2",
                    bcField_3 = "CAT_Custom_3",
                    $formSubmitData = "";

                $radioOptions.on("change", function() {

                    $formButton.removeAttr("disabled"); // enable button

                    var chosenField = $(this).data("field"), // gather value
                        answer_1 = parseInt($existingDataWrapper.data("answer-1")),
                        answer_2 = parseInt($existingDataWrapper.data("answer-2")),
                        answer_3 = parseInt($existingDataWrapper.data("answer-3"));

                    if (chosenField == bcField_1) {
                        answer_1 = answer_1 + 1;
                        $formSubmitData = {
                            ItemName: $webAppItemName,
                            CAT_Custom_1: answer_1,
                            CAT_Custom_2: answer_2,
                            CAT_Custom_3: answer_3
                        };
                    }

                    if (chosenField == bcField_2) {
                        answer_2 = answer_2 + 1;
                        $formSubmitData = {
                            ItemName: $webAppItemName,
                            CAT_Custom_1: answer_1,
                            CAT_Custom_2: answer_2,
                            CAT_Custom_3: answer_3
                        };
                    }

                    if (chosenField == bcField_3) {
                        answer_3 = answer_3 + 1;
                        $formSubmitData = {
                            ItemName: $webAppItemName,
                            CAT_Custom_1: answer_1,
                            CAT_Custom_2: answer_2,
                            CAT_Custom_3: answer_3
                        };
                    }

                    prepForm($formSubmitData);

                });


                function prepForm(formSubmitData) {

                    $formButton.click(function(e) {
                        e.preventDefault();
                        logAnonUserIn("anon", "anon", formSubmitData); // log user in

                    }); // submit

                } // prepForm

                function logAnonUserIn(username, password, formSubmitData) {
                    $.ajax({
                        type: 'POST',
                        url: '/ZoneProcess.aspx?ZoneID=-1&Username=' + username + '&Password=' + password,
                        async: true,
                        beforeSend: function () {},
                        success: function () {},
                        complete: function () {
                            fireForm(formSubmitData);
                        }
                    });
                } // logAnonUserIn

                function fireForm(formSubmitData) {
                    // submit the form

                    var url = "/CustomContentProcess.aspx?A=EditSave&CCID=13998&OID=3931634&OTYPE=35";

                    $.ajax({
                        type: 'POST',
                        url: url,
                        data: formSubmitData,
                        async: true,
                        success: function () {},
                        error: function () {},
                        complete: function () {
                            window.location = "/";
                        }
                    });
                }

            } // pollSubmit

        } // end ui

    };

    Engine.ui.buildChart();
    Engine.ui.pollSubmit();

});

最佳答案

事实证明 easylist 包含这个过滤器:

.aspx?zoneid=

这就是我的脚本被阻止的原因。

有人告诉我可以试试这个异常过滤器:

@@||example.com/ZoneProcess.aspx?*$xmlhttprequest

我也可以要求 easylist 添加一个异常(exception)。

Answer comes from Ad Block Plus Forums.

关于javascript - 广告 block 加上阻止 jQuery 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23569818/

相关文章:

javascript - 如何使用 HTML 表格显示存储在数组中的用户输入数据

javascript - 如何使用twilio客户端在reactjs中发送电话验证码?

javascript - 将文本文件加载和读取到 HTML/JavaScript

Python 将 Adblock 与 Selenium 和 Firefox Webdriver 结合使用

javascript - 检测广告 block 脚本,仅在硬重新加载时正常运行

javascript - Angular JS 和 Node Webkit 路由

javascript - 如何使用 jQuery Mobile 向每个 URL 动态添加参数?

javascript - jQuery 点击功能——选择器的 css 没有被改变

jquery - 如何在 python 中编写自动建议搜索?

javascript - Firebase 脚本被 AdBlock 阻止