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

  • Home
  • SEARCH
  • 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 6602813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:55:19+00:00 2026-05-25T18:55:19+00:00

This is one script that sets the cookie with some html file. window.onload=init; function

  • 0

This is one script that sets the cookie with some html file.

window.onload=init;

function init() {
var userName="";
if(document.cookie != "") {
    username=document.cookie.split("=")[1];
    document.getElementById("name_field").value = username;
}

document.getElementById("name_field").onblur = setCookie;
}

function setCookie() {
var exprDate = new Date();
exprDate.setMonth(exprDate.getMonth() + 6);

var username = document.getElementById("name_field").value;
document.cookie = "username=" + username + ";path=/;expires=" + exprDate.toGMTString();
}

This is another script with some different html file, (that had not saved a cookie in the past) that checks if there is a cookie saved with this document.

window.onload = initTest;

function initTest() {
if(document.cookie == "") alert("No,cookies stored !");
else alert("cookies found !");
}

To my surprise the result when i run the 2nd html file with the second script,is cookies found Why is that ? When that document has not saved a cookie then how come document.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-05-25T18:55:20+00:00Added an answer on May 25, 2026 at 6:55 pm

    Cookies are set per domain and/or path.

    Examples:

    • http://www.example.com/foo.html Cookie: x=x; max-age=3600; is visible at http://www.example.com/*, but not at http://other.example.com/
    • http://www.example.com/foo.html Cookie: x=x; max-age=3600; domain=.example.com is visible at http://*.example.com/* and http://example.com/*
    • https protocols-only: Cookie: x=x; max-age=3600; secure
    • The path can be changed to the current path, or any parent directory. The default path is the current directory. E.g.: x=x; max-age=3600; path=/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one is a real head scratcher for me... var matches = Regex.Matches(<p>test something<script
Google is failing me on this one. Let's say I have some ECMA script
I have a Bash script that basically initializes an application and sets parameters. One
Im trying to create a javascript function that sets the value of one input,
This one boggles my mind. I've used this same script (different targets of course)
I am trying to compile a one-off script, an autogenerated C# program. This program
This MySQL script installs multiple triggers. It works on one machine running MySQL 5.0.51b-community.
i have this script <select> <option value=1>one<img src=star.gif height=15 width=15></img> </option> </select> but it
The problem is this, I include a script, it uses another one, but what
This one will take some explaining. What I've done is create a specific custom

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.