问题
I am creating an applicaiton where I want to access the content of nestend iframe. Say I have a page test.aspx Now there is an iframe say iframe1. and the content of this iframe is another iframe. say iframe2 So its a nested iframe. Now I want to access the content of the iframe2. How we can access the content of this 2nd iframe as I have to search some text in the 2nd iframe. I want to access the iframe with javascript or jquery only.
回答1:
Finally I found the solution.
document.getElementById('iframe1').contentWindow.document.getElementById('iframe2').contentWindow;
and for the innerHTML use
frameElement.contentDocument.activeElement
var iframeFound = document.getElementById('iframe1').contentWindow.document.getElementById('iframe2').contentWindow;
var ifrme = iframeFound.frameElement.contentDocument.activeElement;
来源:https://stackoverflow.com/questions/29910766/access-the-content-of-a-nested-iframe