获取iframe的内容 [英] Getting the contents of iframe
问题描述
我目前正在尝试找到位于iframe中的元素。层次结构是这样的。
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
html > body > form#form1 > iframe#report-container > html > body > form#form1 > div > pageBreaker
(这是一个aspx页面,在aspx页面中,在iframe中使用ascx文件)。
(This is an aspx page, within an aspx page, that uses ascx file within an iframe).
我正试图找到一个好的javascript或Jquery获取pageBreaker元素的方法。
I'm trying to find a good javascript or Jquery method of getting to the pageBreaker element.
我试过:
var jqIframe = $(iframe);
var doc = jqIframe[0].document.form1;
var el = doc.getElementById("pageBreaker"); //undefined
推荐答案
你不需要jQuery来做这必然。
You don't need jQuery to do this necessarily.
var iFrame = document.getElementById('iFrameId').contentDocument;
var desiredElement = iFrame.getElementById('pageBreaker');
使用文档API,我们可以轻松获取iFrame元素并从中提取内容文档。然后通过其ID轻松定位元素。
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.
这篇关于获取iframe的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!