Ldg
Ldg

Reputation: 261

Javascript: retrieve cookies for a particular site

Is it possible in Javascript to save your own cookies that relate to a particular site "www.example.com" and then you can reuse them in another browser?

For example: I save cookies for site "www.example.com" using Javascript in Chrome. I open Firefox and using Javascript I load these cookies and use them.

Upvotes: 0

Views: 957

Answers (3)

Igor S.
Igor S.

Reputation: 3350

Directly no. But you could make a proxy. The scenario is:

  1. User go to webpage, it save cookies in DB
  2. User change browser and open the same website (for ex. uniq url OR some kind of authentication)
  3. Website loads cookies back from DB

in php you can get all cookies using:

print_r($_COOKIE)

If your domain will send this header, your cookies will be avaliable from every domain:

header('Content-type: text/html');    
header('Access-Control-Allow-Origin: *');   

It's not possible to read other domains cookies without their knowledge. If it would be possible it would be security thread. (ex. spam websites read your login information from facebook.com)

Upvotes: 2

Corsair
Corsair

Reputation: 1044

Every browser saves its cookies to his own cookie directory. They usually don't share this with each other, altough you may could set up each browser individually to use one shared cookie directory in which each browser saves its cookies.

As a cookie is nothing else than a text file, each browser should be able to read this if there is no particular difference in the implementation of how the browser saves the cookie to the file system.

If the cookies are compressed or written in other encoding types for example, it won't work.

Upvotes: 0

Oleg V. Volkov
Oleg V. Volkov

Reputation: 22421

There's no JavaScript facilities that are shared between different browsers. You need to use some other storage like Flash for that.

Upvotes: 0

Related Questions