Skip to main content
ha35623707
Participant
March 30, 2021
Answered

Adding Cookie JS to index.html

  • March 30, 2021
  • 2 replies
  • 912 views

I'm having a little trouble adding a JS Cookie to the index.html built with Captivate. Quite frankly, it shouldn't be that difficult considering it's nothing more than <script> content and a file. What happens is that after I've inserted the code, the Cookie container flashes and then the Captivate slider appears but nowhere to be seen is the Cookie container, even though the code is present. However, if I was to load the scripts in a separate web file (as a tester), no problem! I can see and interact with the Cookie prompt.

 

Within the <body>:

<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
cookieconsent.run({"notice_banner_type":"standalone","consent_type":"express","palette":"light","language":"en","website_name":"webname","change_preferences_selector":"#changePreferences","cookies_policy_url":"https://www.fluhah.com/corporate/en/legal/privacy.html"});
});
</script>

 

Loader:

var lJSFiles = [ 'assets/js/jquery-3.3.1.min.js','assets/js/CPM.js','assets/js/cookie-consent.js'];

 

cookie-consent.js (attached as .txt)

 

There are no errors in the console displaying when attempting to make this work. I just can't get the Cookie consent container to appear after the slider loads.

 

Thank you for your assistance!

 

 

This topic has been closed for replies.
Correct answer TLCMediaDesign

Just put this in the head of the html, don't add the js file to the loader section:

 

<script type="text/javascript" src="assets/js/cookie-consent.js"></script>
<script>
window.addEventListener( 'moduleReadyEvent', function( e )
{

cookieconsent.run({"notice_banner_type":"standalone","consent_type":"express","palette":"light","language":"en","website_name":"webname","change_preferences_selector":"#changePreferences","cookies_policy_url":"https://www.fluhah.com/corporate/en/legal/privacy.html"});
});
</script>

2 replies

TLCMediaDesign
TLCMediaDesignCorrect answer
Inspiring
March 31, 2021

Just put this in the head of the html, don't add the js file to the loader section:

 

<script type="text/javascript" src="assets/js/cookie-consent.js"></script>
<script>
window.addEventListener( 'moduleReadyEvent', function( e )
{

cookieconsent.run({"notice_banner_type":"standalone","consent_type":"express","palette":"light","language":"en","website_name":"webname","change_preferences_selector":"#changePreferences","cookies_policy_url":"https://www.fluhah.com/corporate/en/legal/privacy.html"});
});
</script>

ha35623707
Participant
March 31, 2021

Thank you, TLCMediaDesign!

This seems to have fixed the problem!

 

It's awesomely working!

ChrisG LMS
Inspiring
March 30, 2021

Try (with spaces)

 

var lJSFiles = [ @JSFILES_ARRAY , 'assets/js/jquery-3.3.1.min.js' , 'assets/js/CPM.js' , 'assets/js/cookie-consent.js' ];

 

 

ha35623707
Participant
March 31, 2021

The fact that the code loads isn't the problem. The problem is that the Cookie container flashes prior to the Captivate object being visible. After the page loads, the Cookie prompt disappears when it shouldn't and the Captivate is visible. Not the type of functionality expected.