在iframe父界面获取iframe里面的标签
2018-03-12 13:42
776 查看
上一篇里边介绍了在里边利用iframe引入另一个html导航文件,有兴趣的朋友可以看一看 http://www.cnblogs.com/simba-lkj/p/6031662.html
目前遇到一些问题们,想要在引用了iframe的文件里修改iframe里边的样式。
解决了这个问题,整理一下,供大家参考
demo:
<div class=”iframe”>
<iframe src=”header.html” width=”100%” height=”442px” marginwidth=”0” frameborder=”no” scrolling=”no”></iframe>
</div>
1、这是我首先考虑的一个方法
获取iframe引入的html文件元素通过id获取
要在网页加载完之后再进行这段代码
window.onload = function(){
var test = document.getElementById(‘iframe的id’).contentWindow.document.getElementById(‘iframe里要获取的元素的id’);
console.log(test);
test.style.display = “none”;
}
2、可以在iframe文件js里获取父网页的相对路径,将相对路径存储在一个数组中,通过判断相对路径 来进行操作
实例:
var URL = window.parent.location.pathname;
路径数组:
var arrURL = [“/CASE/aishuoke/index.html”,”/CASE/aishuoke/about.html”,”/CASE/aishuoke/news.html”,”/CASE/aishuoke/download.html”,”/CASE/aishuoke/case.html”,”/CASE/aishuoke/job.html”,”/CASE/aishuoke/shownews.html”,
“/CASE/aishuoke/showinfo.html”,”/CASE/aishuoke/showimg_first.html”,”/CASE/aishuoke/showimg_second.html”,”/CASE/aishuoke/showimg_third.html”,”/CASE/aishuoke/showimg_forth.html”];
switch (URL){
case arrURL[0]:
$(”#shouye”).addClass(”show”).siblings().removeClass(”show”);
break;
}
总结:
在iframe中获取父窗口的元素
$(‘#父窗口中的元素ID’, parent.document).click();jquery
在父窗口中获取iframe中的元素
1、:var test = $(“#iframe的ID”).contents().find(“#iframe中的控件ID”);//jquery 方法1
var test2 = $(“#iframe中的控件ID”,document.frames(“frame的name”).document);//jquery 方法2
var test3 = document.getElementById(‘iframe的id’).contentWindow.document.getElementById(‘iframe里要获取的元素的id’);//js方法
转载请注明出处,谢谢合作*-* http://www.cnblogs.com/simba-lkj/p/6032458.html
目前遇到一些问题们,想要在引用了iframe的文件里修改iframe里边的样式。
解决了这个问题,整理一下,供大家参考
demo:
<div class=”iframe”>
<iframe src=”header.html” width=”100%” height=”442px” marginwidth=”0” frameborder=”no” scrolling=”no”></iframe>
</div>
1、这是我首先考虑的一个方法
获取iframe引入的html文件元素通过id获取
要在网页加载完之后再进行这段代码
window.onload = function(){
var test = document.getElementById(‘iframe的id’).contentWindow.document.getElementById(‘iframe里要获取的元素的id’);
console.log(test);
test.style.display = “none”;
}
2、可以在iframe文件js里获取父网页的相对路径,将相对路径存储在一个数组中,通过判断相对路径 来进行操作
实例:
var URL = window.parent.location.pathname;
路径数组:
var arrURL = [“/CASE/aishuoke/index.html”,”/CASE/aishuoke/about.html”,”/CASE/aishuoke/news.html”,”/CASE/aishuoke/download.html”,”/CASE/aishuoke/case.html”,”/CASE/aishuoke/job.html”,”/CASE/aishuoke/shownews.html”,
“/CASE/aishuoke/showinfo.html”,”/CASE/aishuoke/showimg_first.html”,”/CASE/aishuoke/showimg_second.html”,”/CASE/aishuoke/showimg_third.html”,”/CASE/aishuoke/showimg_forth.html”];
switch (URL){
case arrURL[0]:
$(”#shouye”).addClass(”show”).siblings().removeClass(”show”);
break;
}
总结:
在iframe中获取父窗口的元素
$(‘#父窗口中的元素ID’, parent.document).click();jquery
在父窗口中获取iframe中的元素
1、:var test = $(“#iframe的ID”).contents().find(“#iframe中的控件ID”);//jquery 方法1
var test2 = $(“#iframe中的控件ID”,document.frames(“frame的name”).document);//jquery 方法2
var test3 = document.getElementById(‘iframe的id’).contentWindow.document.getElementById(‘iframe里要获取的元素的id’);//js方法
转载请注明出处,谢谢合作*-* http://www.cnblogs.com/simba-lkj/p/6032458.html
相关文章推荐
- 通过WebBrowser获取iframe标签里面的标签
- [置顶] iframe标签的使用并实现切换界面效果
- iframe标签里面的页面元素只读
- iframe获取父级标签及控制父级样式
- 如何获取textarea标签里面的文本 在线等回复
- 浅谈layer的iframe弹窗给里面的标签赋值的问题
- c#正则获取html里面a标签href的值
- JavaScript修改和获取p标签里面内容
- jquery页面点击激发事件获取属性显示在input标签里面
- jQuery获取标签里面的某个文本内容
- 获取页面内iframe里面的元素
- HTML <select>标签如何获取里面的内容
- 【Egret】里使用iframe标签达到内嵌多个web界面
- js点击获取标签里面的id
- js与原生 获取标签 里面的内容区别和checkbox name不一样至少选择一项
- javascript获取iframe框架中页面document对象,获取子页面里面的内容,iframe获取父页面的元素,
- strut2 optiontransferselect 标签使用如何在action中获取list和doublelist里面的数据
- 操作iframe里面的标签内容
- 【nodejs】以iframe做载体获取一个完整的web界面
- 通过JS注入的方式获取title标签里面的内容