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

The Archive Base Latest Questions

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

I’m trying to set some cookies (via javascript) before the browser makes a request

  • 0

I’m trying to set some cookies (via javascript) before the browser makes a request for various resources lower on the page. The following works in Chrome/Firefox, but, not IE:

[some_page.html]

<!doctype html>
<head>
<script>
    var hash=new Date();
    document.cookie='hash=' + hash + ';';
    console.log("From page: " + hash);
</script>
<script src="/test_cookie.php"></script>
</head>
<body></body>
</html>

[test_cookie.php]

console.log('From script: <?=$_COOKIE['hash']?>');

When viewing some_page.html, I see the following in the console (in Chrome/Firefox):

"From page: 1316757967982"
"From script: 1316757967982"

Are there any tricks to get this to work in IE? Like setting defer on the test_cookie.php script tag, or, something else along those lines…?

Thanks!

  • 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:53:23+00:00Added an answer on May 25, 2026 at 6:53 pm

    You could dynamically generate the second script tag and inject it into the page so there’s no way it could start before you had set the cookie. Then, if you’re going to dynamically generate the script tag, it might actually be even better to add “?hash=1316757967982” onto the end of the test_cookie.php src URL so you could be guaranteed that your server gets the hash value (from the URL rather than the cookie). Then, you don’t have to rely on cookie vs. script timing.

    Here’s how you dynamically add a script tag:

    function addScriptTag(url) {
      var s = document.createElement(’script’);
      s.type=’text/javascript’;
      s.src= url;
      document.getElementsByTagName(’head’)[0].appendChild(s);
    } 
    
    addScriptTag("/test_cookie.php?hash=" + new Date());
    

    There is no contract with the browser that it won’t start loading multiple scripts at the same time, there’s only a contract that it will execute statically defined scripts in sequential order so I don’t think your current approach is ever guaranteed to work. Loading multiple scripts in parallel could easily be a desired browser speedup option.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

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.