【发布时间】:2020-04-30 22:31:23
【问题描述】:
网站设置为选择接受 cookie 同意,但当第一次访问者单击接受 cookie 按钮时,除非刷新整个页面,否则不会加载 adsense 代码。
有没有办法实现在点击 cookie 接受按钮后加载广告而不必刷新整个页面?
使用这个cookie同意jquery插件:IHaveCookies
这是我正在使用的允许加载 AdSense 的代码的一部分:
$(document).ready(function() {
$('body').ihavecookies(options);
if ($.fn.ihavecookies.preference('ads') === true) {
var src = "//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
var newScript = document.createElement("script");
newScript.type = "text/javascript";
newScript.setAttribute("async", "true");
newScript.setAttribute("src", src);
document.body.appendChild(newScript);
}
上面的代码确实有效,但在页面刷新之前它不允许广告出现。 是否可以在上述代码中添加“刷新”属性,以使广告在“ihavecookies.preference('ads') === true)”上加载而不刷新页面?
我实现这个的网站可以查看Here
fyi....目前没有为欧盟或加利福尼亚访问者加载广告(但这是一个单独的问题,本主题不讨论)
【问题讨论】:
标签: javascript jquery cookies adsense cookieconsent