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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:31:01+00:00 2026-06-17T12:31:01+00:00

Hi there Stack Overflow users. I have created a nice little script to append

  • 0

Hi there Stack Overflow users. I have created a nice little script to append A/B testing information from their API to one of our session cookies to be stored in our database. This script is working in all browsers but IE (surprise surprise!). This is the code:

<script>
function addTParam() {
  function getCookie(acqsource) {
    var i, x, y, ARRcookies = document.cookie.split(';');
    for (i = 0; i < ARRcookies.length; i++) {
      x = ARRcookies[i].substr(0, ARRcookies[i].indexOf('='));
      y = ARRcookies[i].substr(ARRcookies[i].indexOf('=') + 1);
      x = x.replace(/^\s+|\s+$/g, '');
      if (x == acqsource) {
        return unescape(y);
      }
    }
  }
  if (typeof (abtester) != 'undefined') {
    var experimentId = 0;
    var variationId = 0;
    var variationIdx = -1;
    var activeExpts = abtester.activeExperiments;
    var values;
    var newArray = [];
    for (var i = 0; i < activeExpts.length; i++) {
        experimentId = activeExpts[i];
        if (abtester.variationIdsMap.hasOwnProperty(experimentId)) {
          variationId = abtester.variationIdsMap[experimentId];
          newArray = newArray.concat(variationId);
        }
      }

    newArray = activeExpts.concat(newArray);
    values = newArray.join('-');

    var contents = getCookie('acqsource');
    if (values && values.length > 0 && (contents.indexOf(values) === -1)) {
      contents += "&tp=" + values;
      document.cookie = "acqsource=" + contents + "; domain=domain.com; path=/";
    }
  }
}
$(document).ready(function () {
  addTParam();
});
</script>

To give a bit of an explanation, this function will append a string of “tp=123456-7890123” to the acqsource cookie. However, when it goes to execute the getCookie function, IE either: a) cannot find it, or b) is saying it doesnt exist (which it should, the page creates that cookie on load). This is all being loaded after the DOM is finished, so that isn’t the issue.

I’ve googled this issue exhaustively, and even approached a couple of other devs in my company, and all of us are stumped. Thanks in advance!

  • 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-17T12:31:01+00:00Added an answer on June 17, 2026 at 12:31 pm

    So, I have figured this out. The way that I was checking for the cookies was to check if there was an =. This was the issue, as the way that IE sets session cookies, if the cookie is null, it comes back as undefined as there is no = in that cookie. So a bit of code magic got me this:

    var contents = getCookie('acqsource');
    if (values && values.length > 0 && contents !== undefined && (contents.indexOf(values) === -1)) {
      contents += '&tp=' + values;
      document.cookie = 'acqsource=' + contents + '; domain=domain.com; path=/';
    }
    else if (values && values.length >0 && contents === undefined){
      document.cookie = 'acqsource=' + values + '; domain=domain.com; path=/';
    }
    

    Basically, you need to check if the cookie is undefined, and if not, write and append. However, if the cookie is empty, you need to just add it to it. Hope this can help anyone who ends up in my predicament with session cookies and IE.

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

Sidebar

Related Questions

Hello there Stack Overflow, I hope you'll help me with my very first question
There are various answers on Stack Overflow which explain the conditions under which tail
There are a lot of questions relating to license keys asked on Stack Overflow.
I know there are a thousand data import related questions on Stack Overflow, and
I have tried setting this up based on previously asked questionshere on stack overflow
I've read all the posts on Stack Overflow about CreateProcessAsUser and there are very
I know there are similar question regarding this topic on stack overflow; however, I
Following on from another question on Stack Overflow by a different user, I thought
I know many people have had this problem and I have searched Google/Stack Overflow,
I have a text editor similar to what is used on stack overflow. I

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.