开发者

Access iframe's top html and body tag

开发者 https://www.devze.com 2023-04-12 22:35 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号