0

I have question regarding accessing all browser cookies using javascript, i was able to do this in shell script but i want to access the cookie information stored in local machine which needs to pass to server.

Regards

1
  • 1
    Shell script to access browser cookies? a Typo? Commented Sep 7, 2011 at 14:17

5 Answers 5

3

You can access them using

document.cookies
Sign up to request clarification or add additional context in comments.

1 Comment

ya tried this but it'll give me only the current page cookies, what i need all the browser cookies
3

You cannot access all browser cookies. Only cookies set for the current domain and not marked 'http-only' (or 'secure' if you are on a non-SSL page).

In javascript use document.cookies

Update
The browser has built in functionality, as a security feature, to prevent you from reading cross domain cookies. As long as the javascript runs in the browser, there is no method to access those cookies, let alone execute a shell command. Google for: same origin policy.

What you basically are looking for has so many security/privacy implications, I don't even know where to start explaining the dangers.

3 Comments

I tried document.cookies as you told i got only current domain cookies but i need browser stored cookies. Is there any way to execute shell script or unix commands by javascript??
ok, if i use shell script i can't able to access the local machine cookie file. Am doing this to bypass the sites which asks subscription in php curl() function, do you have any better method to store all cookies of specific domain.
And even it is helpful if you can tell how to access the sqlite database from javascript
3

Imagine that was possible. You browse to an arbitrary site that loads third-party ads, a rogue ad reads all your browser cookies and, voilá!, some guy from the Russian Mafia has the "Remember me" cookies and session IDs for all your sites. He can read your e-mail, see your pics on Facebook and retrieve money from your PayPal account.

2 Comments

Psst! He's the guy from the russian mafia!
That i agree but is there any other way to access all cookies of a specific site using javascript??
2
function getCookie(name) {
  // Split cookie string and get all individual name=value pairs in an array
  var cookieArr = document.cookie.split(";");
  // Loop through the array elements
  for (var i = 0; i < cookieArr.length; i++) {
    var cookiePair = cookieArr[i].split("=");
    /* Removing whitespace at the beginning of the cookie name
        and compare it with the given string */
    if (name == cookiePair[0].trim()) {
      // Decode the cookie value and return
      return decodeURIComponent(cookiePair[1]);
    }
  }
  // Return null if not found
  return null;
}

Comments

0
function listCookies() {
var theCookies = document.cookie.split(';');
var aString = '';
for (var i = 1 ; i <= theCookies.length; i++) {
    aString += i + ' ' + theCookies[i-1] + "\n";
}
return aString;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.