Reputation:
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();
Upvotes: 2
Views: 8349
Reputation: 288260
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.
Upvotes: 5