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 9121309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:49:57+00:00 2026-06-17T05:49:57+00:00

To create a cookie in javascript I use document.cookie = cookieName=cookieValue;expires=myDate;path=/ To read a

  • 0

To create a cookie in javascript I use

document.cookie = "cookieName=cookieValue;expires=myDate;path=/"

To read a cookie: I read many articles in the web including w3schools, but they give complicated codes with for(;;){} method and split. I don’t need such codes. I just need a small javascript code.

If anyone can, please give me a code that will display an alert with the value of 'cookieName' cookie?

  • 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-06-17T05:49:58+00:00Added an answer on June 17, 2026 at 5:49 am

    This may be the easiest way I can give you.

    Call the function it returns cooke value:

          /**     
        * Returns cookie.
        * @param {String} sName Main cookie name.
        * @param {String} SubName Sub cookie name.
        * @return {String} Cookie.     
        */
    
    
    GetCookie: function (sName, SubName) {
            var aCookie = document.cookie.split("; "); // cookies are separated by semicolons
            var CookieVal = null;
            var bHasKeys;
            for (var i = 0; i < aCookie.length; i++) {
                var aCrumb = aCookie[i].split("=");
                bHasKeys = aCrumb.length > 2 ? 1 : 0;
                if (sName == aCrumb[0]) {
                    var TempVal = aCookie[i];
                    TempVal = TempVal.substring(TempVal.indexOf(sName) + sName.length + 1, TempVal.length);
                    if (SubName) {
                        TempArr = TempVal.split("&"); // subcookie seperated by &
                        for (var j = 0; j < TempArr.length; j++) {
                            if (TempArr[j].split("=")[0] == SubName) {
                                CookieVal = TempArr[j].split("=")[1];
                                //while loop is added since /+/g syantax does not work here
                                while (CookieVal.indexOf("+") != -1) CookieVal = CookieVal.replace('+', ' ');
                                CookieVal = unescape(CookieVal);
                                break;
                            }
                        }
                    }
                    else {
                        if (bHasKeys) CookieVal = TempVal;
                        else {
                            CookieVal = aCrumb[1];
                            //while loop is added since /+/g syantax does not work here
                            while (CookieVal.indexOf("+") != -1) CookieVal = CookieVal.replace('+', ' ');
                            CookieVal = unescape(CookieVal);
                        }
                        break;
                    }
                }
            }
            return CookieVal == null ? '' : CookieVal;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my JavaScript code I use to create my cookie............ document.cookie = Name=
If I create a cookie in Javascript document.cookie = 'unseen' how do I delete
I have long read about Use cookie-free domains aka create a subdomain that can
I need help how to use correctly the javascript : document.cookie or how to
i create a cookie and use it like this.inside a document.ready document.cookie = $('#rdb1').attr(id);
How can i create a cookie by using javascript just for end of the
I want to create a cookie using php,an also i need to read it
Im trying to create a 2 dimensional array as a cookie in javascript. Is
I have a cookie and need to read it with JQuery or just javascript
Can I edit a cookie created by JavaScript with PHP and vice versa?

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.