如何使用 Adblock 检测用户并重定向 javascript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18387773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to detect users with Adblock and redirect javascript
提问by Williams A.
I have been searching things about how to detect an ad-block and I found some things but none of them worked. How can I detect an ad-block in my web site and redirect the users? For example:
我一直在搜索有关如何检测广告块的内容,我发现了一些东西,但没有一个起作用。如何检测我网站中的广告拦截并重定向用户?例如:
I have a ad-block, and go to www.lol.com
it should redirects me to www.lol.com/adblock.php
.
我有一个广告块,转到www.lol.com
它应该会将我重定向到www.lol.com/adblock.php
.
Edit
编辑
I just don't have ads, I'm developing a online game but users that have Adblock for some weird reason blocks the game. I just want to detect whether a user uses Adblock and tell these users to disable it.
我只是没有广告,我正在开发一个在线游戏,但是由于某种奇怪的原因使用 Adblock 的用户阻止了游戏。我只想检测用户是否使用 Adblock 并告诉这些用户禁用它。
采纳答案by ataman
If AdBlock hides your ads, you can just check if height of your ad containers is zero:
如果 AdBlock 隐藏了您的广告,您只需检查广告容器的高度是否为零:
$(function() {
if (!$("#yourAdContainer").height()) {
window.location.href = "www.lol.com/adblock.php";
}
});
UPDATE:
更新:
If you have no ads, you can create invisible block with id, known by adblock, of fixed height on page load, and check it's height. Example from my project:
如果您没有广告,您可以在页面加载时创建一个带有 id(由 adblock 知道)的固定高度的不可见块,并检查它的高度。我的项目中的示例:
$(document.body).append('<div id="advblock" style="position: absolute; opacity: 1; top: 0; left: 0;">hh</div>');
setTimeout(function() {
if (!$('#advblock').height()) {
window.location.href = "www.lol.com/adblock.php";
}
$("#advblock").remove();
}, 1);
回答by Bolli
Check if your div containing the game has a "ad like" class
or id
name.
检查包含游戏的 div 是否有“广告”class
或id
名称。
Adblocks filters are big, so if you use class
or id
names that has
Adblocks 过滤器很大,因此如果您使用class
或id
名称具有
ad
or advertising
or something that could hint it was an ad, changes are it will get blocked because of existing filters. This has happened to me. Try renaming them.
ad
或者advertising
可能暗示它是广告的东西,更改它会因为现有的过滤器而被阻止。这发生在我身上。尝试重命名它们。