简体   繁体   中英

Javascript - Document.domain - Does it grab parent or IFrame

Assume for a second I have a website called www.website.com. Then I have an IFrame on that page that loads www.website2.com. Then within that is another iframe that loads www.website3.com. SO at this point we have an Iframe 2-3 levels deep. Assume that within websit3 we have some JavaScript code that calls, and does some stuff with "document.domain". Which domain out of these will we receive back from that call. Will it report the document.domain as website3, or will it be website.com?

Thanks!

Due to the same origin policy, the script in document from website2 won't even be able to access the DOM of website or website3. Even if you could, you would have to try to access them through the frames object in window , or through a reference to the frame itself. For more information on how to do this, check here .

So to answer your question - calling document.domain in website2 (for example) will be the domain of the documents origin, which is website2.

For more information on the same origin policy, you can check out the explanation from Wikipedia or Mozilla docs .

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