Reputation: 2911
I am using a third party library that mandates an iframe with some id, say "x", to load content from their site. And once the content is loaded, the HTML that comes from their site contains a div with the same id - "x". I can not change the iframe id because they need it that way and I have no control over the div's id. How can get to the iframe using native javascript? Will document.getElementById("x") always return the iframe because that's the first element in the dom?
Thanks for the help.
Upvotes: 0
Views: 958
Reputation: 316
An iframe served from a different origin (domain) will create a nested browsing context then its content cannot be inspected from your script and so there is no way to accidentally select the id from inside.
In the case of an iframe from the same origin as the parent document, you may need to explicitly get the iframe contents first and then search that if you want to find the element by that id inside the iframe. Here is an example. The jQuery function '.content()' makes this convenient.
Upvotes: 1
Reputation: 1602
hope, this code would be of any help :)
var frameTag=document.getElementById(iframeid);
if (frameTag.tagName=='IFRAME')
{
//execute your conditions
}
Upvotes: 0