Dharmin
Dharmin

Reputation: 3

Browser issues related to cookie reading from javascript

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

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

Upvotes: 0

Views: 859

Answers (1)

RustyTheBoyRobot
RustyTheBoyRobot

Reputation: 5955

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.

Upvotes: 1

Related Questions