Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6549463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:05:46+00:00 2026-05-25T12:05:46+00:00

So at the moment I am working on setting a cookie in the user’s

  • 0

So at the moment I am working on setting a cookie in the user’s browser… this is how I have done so:

    var cookiename = "benjaminpotter_welcome";
    var cookievalue = "visited";
    var date = new Date();
    date.setTime(date.getTime()+604800000)
    var cookieExpiration = date.toGMTString();
    var cookiepath = "; path=/";
    var myCookie = cookiename + "=" + cookievalue + ";expires=" + cookieExpiration + path;
    document.cookie = myCookie;

And this is how I have attempted to receive it:

    function readCookie(benjaminpotter_welcome) {
     cookieName = cookieName.replace(/([.\\+\-*:\/?!|^${}()\[\]])/g, '\\$1');
     var re = new RegExp('[; ]'+cookieName+'=([^\\s;]*)');
     var sMatch = (' '+document.cookie).match(re);
     if (cookieName && sMatch){ 
     var cookieval = unescape(sMatch[1]);
     }else{
     var cookieval = '';
     };
    };

The thing is that it isn’t working at all…

Here is what I want to happen… I want to set a cookie in the user’s browser called ‘benjaminpotter_welcome’ having the value ‘visited’.

Then I need to request that cookie (on the next page load of course) and test to see whether it = ‘visited’, upon which code will be executed (or in my case not executed.

Here is the part of my website that is not working currently when attempting to use this code:

<script type="text/javascript">
        function readCookie(benjaminpotter_welcome) {
         cookieName = cookieName.replace(/([.\\+\-*:\/?!|^${}()\[\]])/g, '\\$1');
         var re = new RegExp('[; ]'+cookieName+'=([^\\s;]*)');
         var sMatch = (' '+document.cookie).match(re);
         if (cookieName && sMatch){ 
         var cookieval = unescape(sMatch[1]);
         }else{
         var cookieval = '';
         };
        };

$(document).ready(function(){

    $("#thanks").fadeOut(0);
    $("#overlay_big").fadeOut(0);
    readCookie();
    if(cookieval == 'visited'){
    }else{
        $("#overlay_big").delay(2000).fadeIn(1000);
    };
});
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:05:47+00:00Added an answer on May 25, 2026 at 12:05 pm

    You are setting cookieval inside the method, which makes it a private variable. Try:

    function readCookie(cookieName) {
        cookieName = cookieName.replace(/([.\\+\-*:\/?!|^${}()\[\]])/g, '\\$1');
        var re = new RegExp('[; ]'+cookieName+'=([^\\s;]*)');
        var sMatch = (' '+document.cookie).match(re);
    
        return cookieName && sMatch ? unescape(sMatch[1]) : '';
    };
    

    and your DOM-ready:

    $(document).ready(function(){
        $("#thanks").fadeOut(0);
        $("#overlay_big").fadeOut(0);
        var cookieval = readCookie("benjaminpotter_welcome");
        if(!cookieval == 'visited'){
            $("#overlay_big").delay(2000).fadeIn(1000);
        };
    });
    

    should do it.

    If you understood your code, I can recommend the jquery.cookie plugin to work with cookies with javascript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on a project at the moment and we have to implement soft deletion
I'm working in SQLAzure at the moment. I'm setting up a design where each
I am working on a Silverlight app at the moment. I have a few
I found this in the code I'm working on at the moment and thought
At the moment I am working on a project admin application in C# 3.5
I'm working my way into MVC at the moment, but on my To learn
I am working with legacy systems at the moment, and a lot of work
Working on a bunch of forms at the moment and I'm finding that I
For the moment we're still working with the 2.0 framework and and although 2.0
I'm working on a web service at the moment and there is the potential

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.