admin管理员组

文章数量:1287246

I have a page thusly:

<html>
    <head></head>
    <body>
        <iframe src="local.html"></iframe>
        <iframe src=""></iframe>
    </body>
</html>

I've used the DOM to access the first iframe as a test (node.documentWindow) but when I try similar on the external iframe Firebug reports that access is denied.

I suspect this is for XSS protection, but is there a "safe" way to import the node so I can grab an element from that external page? Is there a way to explore the "document as rendered" or something?

Thanks!

I have a page thusly:

<html>
    <head></head>
    <body>
        <iframe src="local.html"></iframe>
        <iframe src="http://www.google."></iframe>
    </body>
</html>

I've used the DOM to access the first iframe as a test (node.documentWindow) but when I try similar on the external iframe Firebug reports that access is denied.

I suspect this is for XSS protection, but is there a "safe" way to import the node so I can grab an element from that external page? Is there a way to explore the "document as rendered" or something?

Thanks!

Share Improve this question edited Jun 26, 2015 at 13:25 Leandro Santiago Gomes 1471 gold badge4 silver badges11 bronze badges asked Mar 3, 2010 at 20:30 Alex McpAlex Mcp 19.3k12 gold badges61 silver badges94 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 13

Nope. Cross domain security prevents this. The only way around is if the surrounding page, and the iframe, are on different subdomains on the same domain. In that case, you can use document.domain.

This is pretty much a given. Imagine the security implications if this were not the case. You could build an iframe containing a user's home banking page, and grab their password using keydown, for example. There's tons of possibilities of misuse.

本文标签: htmlHow can you access an external iframe39s contents via the DOMJavascriptStack Overflow