如何检测我的AdSense广告是否被屏蔽? [英] How can I detect if my AdSense ad is blocked?

查看:366
本文介绍了如何检测我的AdSense广告是否被屏蔽?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户安装了某种广告拦截器,则广告拦截器当然会从我的网站上删除所有广告,并且在以前的广告中留有空白。我想通过在其中添加一些其他内容来使用该空白空间,例如指向我网站最重要页面的链接,以执行此操作,以检测是否已加载AdSense javascript。

If user has some kind of ad blocker installed, ad blocker will of course remove all ads from my website, and it leaves empty spaces where the ads used to be. I would like to use that empty space by putting some other content in it, like links to most important pages of my website, to do that I need to detect if AdSense javascript is loaded.

到目前为止我尝试过的方法:

Methods that I have tried so far:

if (!document.getElementById("google_ads_frame1"))
{
}

和:

if (typeof(window.google_render_ad) == "undefined")
{
}

在某些情况下,这两个方法似乎都失败,例如,如果浏览器下载AdSense javascript文件的速度稍慢,它将在加载AdSense代码之前执行上述代码,我最终为甚至没有被阻止的用户隐藏广告。

Both of those seem to fail in certain situation, for example if browser downloads AdSense javascript files a bit slower, it will execute above mentioned code before AdSense code is loaded and I end up hiding ads for users that don't even have ads blocked.

您对我如何确保我的代码在AdSense之后运行有任何建议吗?还是检测未加载AdSense脚本的其他方法?

Do you have any suggestions on how could I make sure that my code is run after AdSense? Or some other way of detecting that AdSense scripts are not loaded?

推荐答案

窗口上运行此代码.onload 事件。页面完成加载后,会触发 window.onload 事件。

Run this code on the window.onload event. window.onload event is fired when the page has completed loading.

window.onload = function() {
  // your checks
}

如果您使用的是jQuery,请使用

If you're using jQuery, use

$(window).load(function() {
  // your checks
});

这篇关于如何检测我的AdSense广告是否被屏蔽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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