该网站设置为选择接受 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) ”上加载而无需刷新页面?
我实现此功能的网站可以在这里查看
仅供参考......目前没有为欧盟或加利福尼亚访问者加载广告(但这是一个单独的问题,不在此主题中解决)
我正在尝试在 jquery.ui.datepicker 中编辑 beforeShowDay 函数。这是我试图替换的日期选择器中的原始beforeShowDay 行:
beforeShowDay: null, // Function that takes a date and returns an array with
// [0] = true if selectable, false if not, [1] = custom CSS class
name(s) or '',
// [2] = cell title (optional), e.g. $.datepicker.noWeekends
Run Code Online (Sandbox Code Playgroud)
我四处寻找试图找到正确的代码来替换它,但没有运气。我找到了这个小提琴; 在日期选择器中禁用 1 天
我已经编辑了这个小提琴并成功地使用以下代码禁用了星期五和星期六:
$("#datepicker").datepicker({
beforeShowDay: function(date) {
return [date.getDay() == 0 || date.getDay() == 1 || date.getDay() == 2 || date.getDay() == 3 || date.getDay() == 4 ] ;
}
});
Run Code Online (Sandbox Code Playgroud)
但是,当我将其复制并粘贴到 …