What is the difference between using location.hostname and document.domain?
I think an explanation with an example would be helpful.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It seems that
document.domainis a read only property, except in Mozilla, which lets you change the value of the domain that is used for the same origin policy of (for example) AJAX requests without actually updating the page.The restrictions on this are the same rules of the Same Origin Policy.
At least this is my understanding of the MDC docs for
document.domain.From the docs:
Try updating
document.domainandwindow.location.hostnameto a new value in the console, and see the difference.