简体   繁体   中英

Get Cookie of another Domain Javascript

can someone take a look on my snippet and correct me if he know whats i made false. Thank you in advance.

I need to get cookies from a url in javascript.. My approach was to open the url in a new tab and set the cookies to the local storage but theres nothing in the storage

btw this is about a chrome extension

var w = window.open('urlWithCookies');
w.focus();

localStorage.setItem('allCookies', document.cookie);

w.close(); 

Due to the same-origin policy , you cannot read or set cookies, localStorage items and the like for other domains. If it were possible in a certain webbrowser, that would be a gaping security hole and quickly fixed.

Instead, arrange another way to communicate with the website. For instance, the website may use CORS to give you access to some data, or you may contact a web server of yours who then communicates with the website.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM