0

I am facing issues with different browsers when it comes to set cookie and same info is getting from java script.

  • Everything works fine in Firefox i.e. setting the cookie and expiry after 6 months.
  • But in IE cookie do set but expires with browser sessions.
  • For Chrome cookie is not all reading and setting it.

I have tried a lot of experimenting, but I can't get my expected solution. What am I doing wrong?

Dharmin
  • 3
  • 3
  • If a cookie in IE is disappearing at the end of the session, either you're not calculating the EXPIRES attribute correctly, or your page is running in a 3rd party context and you're getting blocked by P3P Policy (click View > Webpage Privacy Policy to see the list of downgraded cookies) – EricLaw Aug 14 '13 at 19:35
  • The error message you're showing above means you have a HTTPS page that used a HTTP URL to download a JavaScript library. HTTPS-pages can't download HTTP-content (for security reasons) in IE, and I believe now both Chrome and Firefox block such downloads too. – EricLaw Aug 19 '13 at 19:10

1 Answers1

1

I don't think this part looks correct:

// Store the cookie
Cookie.prototype.store = function () {
    var cookieval = "";
    for(var prop in this) {
        // ...
        cookieval += prop + ':' + escape(this[prop]);
    };
    // ...
};

Basically, this loops through every global Javascript variable (which has nothing to do with cookies) and adds them to the cookie value. Is that really what you want? Look at the output when I run the following in Chrome:

Chrome output

That's going to be a gigantic cookie.


All of that aside, the error that your seeing looks like a problem with the Same Origin policy. You can't reference Javascript from a domain outside of your page's domain unless the external domain has a special setup. Google has a few servers with that special setup, so if you don't want to host the jquery file on your server, you could use this URL:

https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js

Honestly, though, it seems like you have a lot of issues that you're dealing with (cross domain issues, jQuery being undefined, cross-browser compatibility). You should probably try and simplify your code to see if it works in simple cases. Rather than storing all Javascript variables in a cookie, see if you can just store a simple string value in a cookie and see if your code is cross-browser compatible. If that works, try adding the expiration, then domain/path, etc. This way you can focus on one problem at a time.

RustyTheBoyRobot
  • 5,891
  • 4
  • 36
  • 55
  • It does the same thing in Firefox. I've updated my answer a bit. – RustyTheBoyRobot Aug 16 '13 at 14:54
  • Yes library reference to the same page domain has helped resolved the issue. Thanks again. – Dharmin Aug 20 '13 at 06:14
  • The URL where you serve out your jQuery library doesn't matter; you just have to use the same URL in your `` – RustyTheBoyRobot Aug 22 '13 at 14:19
  • Also, just like EricLaw stated, your page is accessed via HTTPS; therefore the Google URL also has to be HTTPS: (`https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js`). Just FYI. – RustyTheBoyRobot Aug 22 '13 at 14:25
  • I have no idea. The code you posted doesn't have anything to do with hub.js. – RustyTheBoyRobot Sep 02 '13 at 15:32
  • Everything seems fine now and the error was called "evil comma of doom"... Interesting to learn -> http://stackoverflow.com/questions/5139205/javascript-can-a-comma-occur-after-the-last-set-of-values-in-an-array – Dharmin Sep 16 '13 at 08:19