简体   繁体   English

在iframe的src内的视图内处理html元素

[英]Manipulating the html elements inside the view which is inside the src of iframe

I have an iframe inside a view and in the src of the iframe I am rendering another view. 我在视图内有一个iframe,在iframe的src中,我正在渲染另一个视图。 Now I want to get the data of header h2 which is having some id and is present inside the second view rendered inside the src of the iframe. 现在,我想获取标头h2的数据,该标头具有一些ID,并存在于iframe的src内部呈现的第二个视图中。 Please help me out with your ideas and suggestions 请帮我解决您的想法和建议

Examples to access your iframe document: 访问iframe文档的示例:

var frame = document.getElementsByTagName("iframe")[0].contentDocument; // first iframe in page
// or
var frame = window.frames["myFrame"].document; // if your frame has the name "myFrame"
// or
var frame = document.getElementById('myFrame').contentWindow.document; // if your frame has the id "myFrame"

Then you can access your H2 tag inside the iframe with: 然后,您可以使用以下方法在iframe中访问H2标签:

 var h2 = frame.getElementsByTagName("h2")[0];

jQuery solution: jQuery解决方案:

 var frame = $("selector").contents(); // where selector is "#myFrameID" or ".myFrameClass", etc...
 var h2 = frame.find("h2");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM