How to use DOM JavaScript to apply events onclickto links inside iframe?
Here is what I'm trying to not work:
document.getElementById('myIframe').contentDocument.getElementsByTagName('a').onclick = function();
No errors seem to be thrown, and I have full control of the material in iframe.
Here is what code to check and see if I can even calculate how many are divin mine iframe.
var docBody = document.getElementsByTagName("body")[0];
var embed_results = document.createElement('iframe');
embed_results.id = "myIframe";
embed_results.setAttribute("src", "http://www.mysite.com/syndication/php/embed.php");
docBody.appendChild(embed_results);
alert(document.getElementById("myIframe").contentDocument.getElementsByTagName('div').length);
source
share