Getting the contents of iframe

拟墨画扇 提交于 2019-12-02 14:51:22

问题


I'm currently trying to find the element located in an iframe. The hierarchy goes like this.

html > body > form#form1 > iframe#report-container > html > body > form#form1 > div > pageBreaker

(This is an aspx page, within an aspx page, that uses ascx file within an iframe).

I'm trying to find a good javascript or Jquery method of getting to the pageBreaker element.

I've tried:

var jqIframe = $(iframe); 
var doc = jqIframe[0].document.form1; 
var el = doc.getElementById("pageBreaker"); //undefined 

回答1:


You don't need jQuery to do this necessarily.

var iFrame = document.getElementById('iFrameId').contentDocument;
var desiredElement = iFrame.getElementById('pageBreaker');

Using the document API we can easily get the iFrame element and pull the content document out of it. Then it is trivial locating an element via its ID.



来源:https://stackoverflow.com/questions/40152941/getting-the-contents-of-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!