¿JS tiene acceso al dominio desde el que se cargan?

Tengo una pagina 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?

preguntado el 28 de agosto de 12 a las 11:08

1 Respuestas

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 pero no en example.com, because the document is sample.com. You can tell what the relevant domain is using the document.domain propiedad.

Respondido 28 ago 12, 11:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.