1

I have a page http://www.sample.com/load.html ,which loads javscript file http://example.com/test.js which contains code for writing cookies on page , will I be able to create a cookie for http://www.sample.com.

CAn JS access the domain from where they are loaded or only those domain on which JS file is loaded?

1 Answer 1

2

Javascript can (with only a couple of exceptions such as CORS) only access the domain of the document. The origin of the Javascript is irrelevant.

So yes, in this case, you will be able to set cookies on sample.com but not on example.com, because the document is sample.com. You can tell what the relevant domain is using the document.domain property.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy