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.
Getting the element in IframegetElementById() method by passing iframe id as an argument. const iframe = document. getElementById("myIframe"); Now, it has and contentWindow property which returns the document object by using that we can access the elements from an Iframe.
# jQuery Code to Get HTML Content of IFrame contents(). find("html"). html()); }); The above code will return all the HTML content of our Iframe.
In short, to check if a page is in an iframe, you need to compare the object's location with the window object's parent location. If they are equal, then the page is not in an iframe; otherwise, a page is in an iframe.
If you want to display specific area of external website using iframe, then you will learn in this article how to embed a specific part of a web page using css. Suppose, you want to show only one div element from another website and want to hide some specific content, then you can easily do this using <iframe> tag.
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
$('#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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With