9

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.

3

1 Answer 1

24

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 :

 $('#test1', parent.document).html('<h1>clicked</h1>');

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.

2
  • it's not same domain, first is ebay.co.uk and iframe is vi.vipr.ebaydesc.com May 28, 2014 at 14:13
  • Then you can't do it. Click on the link in his answer, please.
    – ndugger
    May 28, 2014 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.