【发布时间】:2016-05-17 18:07:39
【问题描述】:
我在 div 中有一个 AdSense,并希望保护它免受无效流量的影响。 有人点击广告后,应将其隐藏,一段时间后不再显示。
HTML:
<div id="codeWrapper">
<div id="firstCode">Adsense code here</div>
</div>
CSS:
#codeWrapper { position: relative;}
#firstCode { position: absolute; width: 336px; height: 280px; z-index: 999;}
JS:
$("#firstCode").click(function () {
var date = new Date();
var h = "24";
date.setTime(date.getTime() + (h * 60 * 60 * 1000));
Cookies.set('clicked', 'true', {expires: date, path: '/'});
$(this).parent().remove();
});
我使用 javascript cookie 来存储点击广告的日期并设置到期时间。
控制台中没有错误,但不知何故它不起作用。
【问题讨论】:
-
如果你
console.log($(this).parent());你得到了什么?codeWrapper? -
当广告在新标签页中打开时,它不会记录任何内容。当广告开始重定向到另一个网址时也是如此。
-
如果我删除 iframe 并单击,这就是我得到的:
[div#codeWrapper, selector: "", prevObject: a.fn.init[1], context: div#firstCode]
标签: javascript jquery css iframe cookies