Access iframe's top html and body tag
I have the following iFrame structure , I want to access the html and body tag of top html, so I can sroll view top in click of button inside iframe.
<html>
<body>
<div>
<iframe>
<html>
<body>
content
<input>button</input>
</body>
</html>
开发者_C百科 </iframe>
</div>
</body>
</html>
Use the top
object (which only works at the same domain):
var topDocument = top.document;
//do anything you want
//Example:
topDocument.documentElement; //Returns a reference to the HTML element
topDocument.body; //Returns a reference to the top's body
If you want to access the very first HTML element, use this:
$("html:first")
And if you need to access the other HTML element through the iframe you can use this: $("iframe").children("html")
$("iframe").children("html")
You can use "top" keyword.
Like
top.id.document
where id is the 'id' of any element in top html of iframe.
You need to access that from the source of iframe's html.
精彩评论