The iframe is something like this:
<iframe frameborder="0" 开发者_StackOverflow社区src="http://www.another-domain.com/whatever.php">
<html>
<head>Header</head>
<body>
<div div="mydiv">text</div>
</body>
</html>
</iframe>
I want to access #mydiv from the parent window. The iframe contents are from another domain.
Hmmm... from a totally different domain? If so, then I'm afraid you won't be able to do this. That's called "cross-site-scripting" and browsers don't allow that to happen.
However, if you are parent-page is parent.domain.com
and your child is on child.domain.com
, then you can access the contents of the iframe using the window
object:
child_frame = document.getElementById('myFrameId');
inner_div = child_frame.document.getElementById('mydiv');
/* now do stuff with inner div */
I'm pulling that off the top of my head: YMMV!
If its cross-domain id ont think youll be able to do it. Iframes are subject to the same "same domain" policies as ajax i believe.
精彩评论