JS synchronization cookies across domains

Source: Internet
Author: User
Tags cookie names valid

JS cross-domain synchronization cookie How to achieve

Document.cookie = "Name=" + "value" + "expires=" + "datatime" + "domain=" + "" + "path=" + "/path" + "; Secure ";
Name Cookie Names
Value Cookie Values
Expires valid until (in milliseconds)
Path subdirectory
Domain valid field
Secure is safe

<iframe src= ' http://website: 1234/test/index ' width= ' height= ' style= ' Display:none ' ></iframe>

The original page js window.location = "http://another website: 1234/getcookie/index?" + Document.cookie;

Jump to another station,

Another station gets the cookie, sets the cookie

var url = window.location.toString ()//Get Address
var get = url.substring (Url.indexof ("Liuph"))//getting variable and variable values
var idx = get.indexof ("=");//Get Variable name length
if (idx!=-1) {
var name = get.substring (0, IDX);//Get variable name
var val = get.substring (idx + 1);//Get variable Value
Setcookie (Name, Val, 1);//Create Cookie
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.