我正在尝试实施Insites Cookie Consent script(选择加入版本)并在用户接受cookie后加载一些javascript脚本。
实现脚本不是问题,但我最终没有加载javascript。我的cookieconsent代码:
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js"></script>
<script>
window.addEventListener("load", function(){
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#252e39"
},
"button": {
"background": "#14a7d0"
}
},
"position": "bottom-left",
"type": "opt-in",
"content": {
"message": "This site uses cookies",
"dismiss": "I don't want cookies",
"allow": "I accept",
"link": "Privacy policy"
},
onInitialise: function (status) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type == 'opt-in' && didConsent) {
// enable cookies
$(".loadlaterscripts").attr("type", "text/javascript");
}
},
onStatusChange: function(status, chosenBefore) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type == 'opt-in' && didConsent) {
// enable cookies
location.reload();
}
},
})});
</script>
我使用以下代码实现了一些脚本和小部件:
<script type="text/plain" class="loadlaterscripts" src="//link-to.script/file.js"></script>
在控制台中,我可以看到type属性在接受cookie后成功更改为text / javascript,但之后没有任何脚本可用。例如,这适用于Google Adsense脚本,也包括网站提供的简单嵌入代码。
我在这里有什么东西可以忽略吗?