Loading external script on click (after page load) when in auto-blocking mode
I am using Cookiebot in auto blocking mode. For one particular case (an embedded twitter timeline) I need to do things manually. I would like to do the following regardless of the user's choice in the Cookiebot banner:
- show an "allow twitter" button in a placeholder div
- upon click, load the twitter script & initialize the timeline widget
If I accept marketing and preferences cookies in the CB banner this works fine, but if not the getScript call is blocked regardless of the "ignore" data attribute.
More extensive description in stackoverflow
Is what I am trying to do possible or do I have to resort to manual config for all other site cookies?
<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 );
twttr.widgets.load().then(function () {
console.log('Embedded timeline.')
});
});
});
</script>
Please sign in to leave a comment.
Comments
2 comments