我在自动阻止模式下使用 Cookiebot。
对于一个特殊情况(嵌入式推特时间线),我需要“手动”做一些事情。无论用户在 Cookiebot 横幅中的选择如何,我都愿意执行以下操作:
- 在占位符 div 中显示“允许 twitter”按钮
- 单击后,加载 twitter 脚本并初始化时间线小部件
如果我接受 CB 横幅中的营销和偏好 cookie,则以下工作正常,但如果不接受,则 getScript 调用被阻止。
<div class="twitter-wrap">twitter anchor element</div>
<script data-cookieconsent="ignore">
// append a button to allow user to accept cookies
$(".twitter-wrap").append('<div class="twitter-consent"><button class="twitter-consent-btn">Accept</button></div>');
$(".twitter-consent-btn").on("click", function(){
$(".twitter-consent").hide();
$.getScript( "https://platform.twitter.com/widgets.js", function( data, textStatus, jqxhr ) {
console.log( jqxhr.status ); // This is never executed
twttr.widgets.load().then(function () {
console.log('Embedded timeline.')
});
});
});
</script>
我还尝试用twitter 上的建议替换 getScript 调用,在那里我还在动态生成的脚本中添加了忽略标志)但没有成功:
function append_twttrScript() {
window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.setAttribute("data-cookieconsent", "ignore"); // Here I add an extra attribute
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
t._e = [];
t.ready = function(f) {
t._e.push(f);
twttr.widgets.load().then(function (el) {
console.log('Embedded a timeline.')
});
};
return t;
}(document, "script", "twitter-wjs"));
}
据我了解, data-cookieconsent="ignore" 的工作原理是它先使用该标志执行一次脚本,然后阻止所有内容?!
我需要做的事情是可能的还是我需要对 cookiebot 进行手动配置?