该网站设置为选择接受 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);
}
Run Code Online (Sandbox Code Playgroud)
上面的代码确实有效,但它不允许广告在页面刷新后出现。是否可以在上述代码中添加“刷新”属性,以使广告在“ ihavecookies.preference('ads') === true) ”上加载而无需刷新页面?
我实现此功能的网站可以在这里查看
仅供参考......目前没有为欧盟或加利福尼亚访问者加载广告(但这是一个单独的问题,不在此主题中解决)