Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Wanted: Script for cookie consent pop up message.

  1. #1
    Join Date
    Feb 2005
    Posts
    71
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Wanted: Script for cookie consent pop up message.

    Google has told me that I need to obtain EU end users’ consent to the storing and accessing of cookies and other information if I want to continue using AdSense.

    They have suggested links to various sites that offer scripts for pop up bars that disappear when you accept cookies (such as https://silktide.com/tools/cookie-consent/download/) but they don't allow me to customise the font and colours.

    Can anyone suggest where I might be able to get a simple customiseable script? All I want is a simple bar at the top of the page with a message saying "This site uses cookies etc. " a link to "more info", and an "OK" button which makes the bar and message disappear when clicked.

    Thanks

    Rob

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Feb 2005
    Posts
    71
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Beverleyh View Post
    Thank you very much indeed, Beverley! That is just what I was after.

    I understand all the HTML and CSS but I know very little about JS. Can I put the script into an external file and link to it, to save having to paste all the code into every page? And if so, how would I save the external file using notepad?

    Also, if I've inserting the JS inline, does it matter where it goes or can I put it anywhere?

    Thank you again.

    Rob

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Yes you can save it into an external file. For that you would open up Notepad (I think that's in Programs >> Accessories?) and copy+paste the JavaScript into it - just the code between the <script></script> tags - then save it with the .js extension. So you might call the file "cookie.js". You can type the full file name, including the .js extension, into the field for the file name when you save from Notepad. Then you upload the "cookies.js" file to your web server - let's say you save it in the main folder of your website. You would link to it from within your web page(s) like this;
    Code:
    <script src="/cookie.js"></script>
    You should put this JavaScript link reference above the closing </body> tag (it's preferred that way for almost all JavaScripts nowadays, so that the rest of the page can render without being blocked waiting for scripts to load).

    Hope that helps
    Last edited by Beverleyh; 08-23-2015 at 09:05 AM. Reason: js position correction
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  5. #5
    Join Date
    Dec 2008
    Location
    Selby, North Yorkshire
    Posts
    90
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Default

    Sorry Bev I can't get this to work.

    Here's my test page;
    http://www.castlefordheritagetrust.org.uk/zSandPit.php

    I thought the problem might be with this line;
    document.cookie = "consent=ok;path=/;expires="+d.toGMTString();

    So I moved the js file to the root directory and it still doesn't work.

    Where am I going wrong?

    John

  6. #6
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    You've missed some of the code in the cookies.js file - there should be a line which adds a class of "js" to the <html> tag, and 3 lines where the variables are defined for cookie, btn and bar.

    Have another look at the source of the demo page http://fofwebdesign.co.uk/template/_...ie-consent.htm and copy+paste the whole code block (but not the block for my Google Analytics.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  7. The Following User Says Thank You to Beverleyh For This Useful Post:

    BorderTerroir (08-23-2015)

  8. #7
    Join Date
    Dec 2008
    Location
    Selby, North Yorkshire
    Posts
    90
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Default

    Sorry Bev I'm still not there.

    My js file now reads like this;
    Code:
    document.documentElement.className = 'js'; // adds .js class to <html> tag
    
    var cookie = getCookie('consent'),
        bar = document.getElementById('consent'),
        btn = document.getElementById('ok');
    
    btn.onclick = function() { // hide bar and set cookie when button is clicked
    	bar.style.display = 'none';
    	var d = new Date; 
    	d.setTime(d.getTime()+24*60*60*1000*90); // 90 days
    	document.cookie = "consent=ok;path=/;expires="+d.toGMTString();
    	}
    
    function getCookie(name) {
    	var v = new RegExp(name+"=([^;]+)").exec(document.cookie);
    	return (v != null) ? unescape(v[1]) : null;
    	}
    
    bar.style.display = (cookie == 'ok') ? 'none' : 'table'; // hide bar if cookie is set
    But it still doesn't work.

    http://www.castlefordheritagetrust.org.uk/zSandPit.php

    John
    Last edited by Beverleyh; 08-23-2015 at 10:34 AM. Reason: Formatting

  9. #8
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Correction - put the link reference to the JS file before the closing </body> tag.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  10. The Following User Says Thank You to Beverleyh For This Useful Post:

    BorderTerroir (08-23-2015)

  11. #9
    Join Date
    Dec 2008
    Location
    Selby, North Yorkshire
    Posts
    90
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Default

    Many thanks that's sorted it.

    You are a star!

  12. #10
    Join Date
    Feb 2005
    Posts
    71
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Bev, thank you so much for your help. I've just added the code to http://www.curiouser.co.uk and it's working fine but I have a small issue. When I view the site on an iPad (Chrome and Safari) the bar does not stretch the full length of the screen - it only goes about 95% of the way across. Any ideas why this might be? I doesn't do it on your site but I can't work out what is making it do it on mine.

    Rob

Similar Threads

  1. alert box script wanted
    By paldo in forum JavaScript
    Replies: 8
    Last Post: 06-25-2011, 07:03 AM
  2. Script wanted?
    By techker in forum PHP
    Replies: 2
    Last Post: 03-09-2010, 02:05 PM
  3. D'ling files on to your pc without consent?
    By hmsnacker123 in forum The lounge
    Replies: 10
    Last Post: 04-02-2009, 03:41 PM
  4. Script wanted
    By loveit123 in forum Looking for such a script or service
    Replies: 2
    Last Post: 10-03-2008, 06:52 PM
  5. script wanted
    By forgetmenow in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 04-04-2007, 12:59 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •