It may be an ugly solution, but at least it works, and in fact it is quite simple:
// Create container to store iframes' inner HTML and to be able to work with it var container = document.createElement("div"); // Add HTML of first iframe to container container.innerHTML = document.querySelector("#num1").innerHTML; // Add HTML of nested (second) iframe to container container.innerHTML = container.querySelector("#num2").innerHTML; // Finally get href attribute var href = container.querySelector("#div2 a").getAttribute("href"); console.log(href);
Most modern browsers already support querySelector() , you will have problems with older IEs. See http://caniuse.com/queryselector .
Edit: This code is based on the following idea: Get the iframe HTML content and copy / paste it into the div element to be able to directly execute requests for it (so we donβt have to worry about getting the iframe document object). When this is done with the first iframe, we will repeat it for the second (nested) iframe. Then we can simply read the attribute of the desired elements. querySelector() can be used almost like a jQuery selector (for example, $("#id") ).
source share