简体   繁体   中英

How to get an element outside of iframe with javascript or jQuery?

I'm trying to get a element from outside of iframe with js or jQuery. I found something but it's not cross browser.

<div id=vi-desc-maincntr"">
    <div class="u-flL iti-act-num">123456789</div>
    <div id="desc_div">
        <iframe src="LOCATION">
    </div>
</div>

I need that number into a variable.

Same-origin policy :
You might want to check this. Two pages need to have the same origin.
https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy


If your child page is located at same domain as parent page, You can write a code like below in the child window :

 jQuery( selector [, context ] )

The second parameter provides the context in which to search the element matched by the first parameter. The Document is here: http://api.jquery.com/jQuery/#jQuery-selector-context

  jQuery( selector [, context ] ) 

Hope this helps.

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