检测adblock和javascript [英] Detect adblock and javascript

查看:65
本文介绍了检测adblock和javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在我的网站上检测广告拦截软件,并要求用户通过重定向禁用广告拦截.我发现的唯一方法是使用Javascript.

I wish to detect adblocking software on my website and ask users to disable adblock by redirecting. The only way I found was using Javascript.

  1. 还有其他检测方法吗?

  1. Is there any other way of detection ?

如果没有,如何检测Javascript是否被禁用并将其重定向到某个页面?

If not, how do I detect if Javascript is disabled and redirect them to a certain page ?

推荐答案

如果禁用了javascript,则实际上无法检测".由于javascript是客户端功能,因此服务器无法检测到它,而检测"客户端的操作是使用javascript完成的.您会看到渔获22.

You cannot actually "detect" if javascript is disabled. Since javascript is a client-side feature, the server cannot detect it, and "detecting"things client-side is done with javascript. You see the catch 22.

可用的是< noscript> 标记,只有在关闭javascript的情况下,该标记才由浏览器呈现.如果禁用了javascript,这是向用户显示消息的标准机制.使用noscript和灵巧的CSS,您可以使用户必须启用javascript或遵循您提供的重定向链接才能使用您的网站.

What is available is the <noscript> tag, which is only rendered by the browser if javascript is turned off. This is the standard mechanism for displaying a message to a user if javascript is disabled. Using noscript and clever CSS you can make it imperative that users either enable javascript or follow a redirect link you present to use your site.

无法自动重定向仅禁用了JavaScript的 用户.您可以使用javascript有选择地重定向用户,也可以根据服务器端条件(HTTP标头等)重定向用户.但是你不能抓住那个中间群体.

There is no way to automatically redirect only users that have javascript disabled. You can redirect users selectively by using javascript, or you can redirect people based on server-side criteria (HTTP headers, etc.). But you can't catch that middle group.

对于检测广告屏蔽,这将因浏览器和广告屏蔽方法而有所不同.没有一个一致的标记,但是您可以执行一些操作,例如通过javascript检查广告服务器的可用性,或者检查广告内容是否已加载到页面上.

As for detecting adblocking, this is going to vary by browser and adblocking method. There isn't a consistent flag for it, but you can do things like checking for the availability of your ad server via javascript, or checking if your ad content is loaded on the page.

这篇关于检测adblock和javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆