if (window.parent && window.parent.frames["frame_main"]) {
alert(window.parent.frames["frame_main"]);
window.parent.frames["frame_main"]..location.reload();
}else
{
window.parent.frames.item("frame_main").location.reload();
}
if (window.parent && window.parent.frames["frame_main"]) {
alert(window.parent.frames["frame_main"]);
window.parent.frames["frame_main"].location.reload();
}
else if (window.parent && window.parent.frames.item("frame_main")) {
window.parent.frames.item("frame_main").location.reload();
}
//刷新父窗口
window.parent.frame_main.location.reload();
iframe父子兄弟之间调用传值(contentWindow && parent)
学习一个知识点最好的方法就是自己动手去的实现一些简单的helloworld,虽然可以在网上可以找到很多总结,但自己实现的过程才是自己的,期间遇到问题并解决问题的过程也会让自己记忆理解更加深刻。
iframe的调用包括以下几个方面:(调用包含html dom,js全局变量,js方法)
主页面调用iframe;
iframe页面调用主页面;
主页面的包含的iframe之间相互调用;
主要知识点
1:document.getElementById("ii").contentWindow 得到iframe对象后,就可以通过contentWindow得到iframe包含页面的window对象,然后就可以正常访问页面元素了;
2:$("#ii")[0].contentWindow 如果用jquery选择器获得iframe,需要加一个【0】;
3:$("#ii")[0].contentWindow.$("#dd").val() 可以在得到iframe的window对象后接着使用jquery选择器进行页面操作;
4:$("#ii")[0].contentWindow.hellobaby="dsafdsafsdafsdafsdafsdafsadfsadfsdafsadfdsaffdsaaaaaaaaaaaaa"; 可以通过这种方式向iframe页面传递参数,在iframe页面window.hellobaby就可以获取到值,hellobaby是自定义的变量;
5:在iframe页面通过parent可以获得主页面的window,接着就可以正常访问父亲页面的元素了;
6:parent.$("#ii")[0].contentWindow.ff; 同级iframe页面之间调用,需要先得到父亲的window,然后调用同级的iframe得到window进行操作;
源码
main.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> < html >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" >
< title >显示图表</ title >
< script src = "http://www.cnblogs.com/http://www.cnblogs.com/scripts/jquery-1.7.1.min.js" type = "text/javascript" ></ script >
< script type = "text/javascript" >
var gg="dsafdsafdsafdsafsdaf";
function ggMM() {
alert("2222222222222222222222222222222");
}
function callIframeMethod() {
//document.getElementById("ii").contentWindow.test();
$("#ii")[0].contentWindow.test(); //用jquery调用需要加一个[0]
}
function callIframeField() {
alert($("#ii")[0].contentWindow.ff);
}
function callIframeHtml() {
alert($("#ii")[0].contentWindow.$("#dd").val());
//alert($("#ii")[0].contentWindow.document.getElementById("dd").value);
//alert($("#ii")[0].contentWindow.document.getElementById("dd").value);
}
function giveParameter() {
$("#ii")[0].contentWindow.hellobaby="dsafdsafsdafsdafsdafsdafsadfsadfsdafsadfdsaffdsaaaaaaaaaaaaa";
}
</ script >
</ head >
< body >
< a href = "#" onClick = "giveParameter();" >参数传递</ a >
< a href = "#" onClick = "callIframeMethod();" >调用子iframe方法</ a >
< a href = "#" onClick = "callIframeField();" >调用子iframe变量</ a >
< a href = "#" onClick = "callIframeHtml();" >调用子iframe组件</ a ></ br >
< iframe id = "ii" src = "frame.htm" width = "100%" frameborder = "0" ></ iframe >
< iframe id = "new" src = "newFrame.htm" width = "100%" frameborder = "0" ></ iframe >
</ body >
</ html >
|
frame.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> < html >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" >
< title >显示图表</ title >
< script src = "http://www.cnblogs.com/http://www.cnblogs.com/scripts/jquery-1.7.1.min.js" type = "text/javascript" ></ script >
< script type = "text/javascript" >
var ff="adfdasfdsafdsafdsaf"; function test() { alert($("#dd").val());
} function callMainField() { alert(parent.gg);
} function callMainMethod() { parent.ggMM();
} function callMainHtml() { alert(parent.$("#ii").attr("id"));
} function getParameter() { alert(window.hellobaby);
} </ script >
</ head >
< body >
< a href = "#" onClick = "getParameter();" >接受参数</ a >
< a href = "#" onClick = "callMainMethod();" >调用子iframe方法</ a >
< a href = "#" onClick = "callMainField();" >调用主窗口变量</ a >
< a href = "#" onClick = "callMainHtml();" >调用子iframe组件</ a >
< input id = "dd" type = "text" value = "1111111111" />
</ body >
</ html >
|
兄弟iframe页面 newIframe.htm
![js调用父框架函数 js调用父框架函数](https://image.shishitao.com:8440/aHR0cDovL2Jic21heC5pa2FmYW4uY29tL3N0YXRpYy9MM0J5YjNoNUwyaDBkSEJ6TDJOdmJXMXZiaTVqYm1Kc2IyZHpMbU52YlM5cGJXRm5aWE12WTI5d2VXTnZaR1V1WjJsbS5qcGc%3D.jpg?w=700&webp=1)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>显示图表</title>
<script src="http://www.cnblogs.com/http://www.cnblogs.com/scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
function callLevelFrame() {
var ff=parent.$("#ii")[0].contentWindow.ff;
alert(ff);
}
</script>
</head>
<body>
<a href="#" onClick="callLevelFrame();">调用兄弟iframe</a>
<input id="nn" type="text" value="sdafsdfsa"/>
</body>
</html>
![js调用父框架函数 js调用父框架函数](https://image.shishitao.com:8440/aHR0cDovL2Jic21heC5pa2FmYW4uY29tL3N0YXRpYy9MM0J5YjNoNUwyaDBkSEJ6TDJOdmJXMXZiaTVqYm1Kc2IyZHpMbU52YlM5cGJXRm5aWE12WTI5d2VXTnZaR1V1WjJsbS5qcGc%3D.jpg?w=700&webp=1)
结语:
我对jquery html css的理解还需要很多提高,自己总结的东西对大牛来说也很幼稚,但大牛之路都是如此总结向上提高的,我不怕这种幼稚。
js调用父框架函数与弹窗调用父页面函数的方法
调用父级中的 aaa的函数
子页面中:
onclick="window.parent.frames.aaa()"
父页面中:
function aaa()
{
alert(‘bbbbb’);
}
----------------------------------------------
frame框架里的页面要改其他同框架下的页面或父框架的页面就用parent
window.opener引用的是window.open打开的页面的父页面。
window.frames对象可以引用iframe里的页面,也可以引用frameset里的页面.
可以这样
window.frames[0].document.getElementById(‘xx’);
可以这样
window.frames[0].document.body.innerHTML;
frm = window.parent.window.frames[‘uploadFrame’];
frmDocument = frm.document;
frm.sb(3); //sb 是uploadFrame页面里的一个函数
对于firefox
如果你遇到报错:parent.document.frames has no properties
换为如下代码就可以了,这个代码IE,ff兼容. frm = window.parent.window.frames[‘uploadFrame’];其实 frames 集合并不是挂在 document 而是挂在 window 对象下.
注意这样修改frame里的页面有限制,就是必须是同域下的,否则无法访问
如果是同一域下,但是子域名不同,那么涉及到的js,html文件都加上一句。
document.domain = xxx.com [这里填写你的域名]
document.getElementById(‘iframeid’).contentWindow.document.getElementById(‘someelementid’);
js弹窗页面后调用父页面函数
(例如:调用父页面函数test2())
window.opener.test2();
框架子页面调用上一个页面方法
(例如:上一页面的框架frame名为menuBar,调用onhook()函数)
window.top.frames["menuBar"].onhook();
js弹窗页面调用父页面框架子页面函数
(如:弹窗页面调用,frame名为menuBar)
window.opener.top.frames['menuBar'].onhook();
js调用父框架函数的更多相关文章
-
iframe调用父页面函数用法举例
iframe如何调用父页面函数. window.parent.xxxxx();//xxxxx()代表父页面方法具体列子如下,其中包括easyUI的右键和单击事件parent.jspbody部分代码 & ...
-
js调用父窗口中的方法
window.open调用父窗口中的方法 回调函数: function fun9(ex){ alert(ex); } 调用语句: window.open("RoomSelecter.htm? ...
-
js调用父级frame中的方法
父级frame中的方法: function hideOutline() { $("#outline").hide(); $("#content").attr(& ...
-
关于Vue中,父组件获取子组件的数据(子组件调用父组件函数)的方法
1. 父组件调用子组件时,在调用处传给子组件一个方法 :on-update="updateData" 2. 子组件在props中,接收这个方法并声明 props: { onUp ...
-
js 调用父窗口的方法
opener.show(); 父窗体需要顶一个show() 方法 父面页代码: <!DOCTYPE HTML PUBLIC "-//IETF//DTD LEVEL1//EN" ...
-
js从$scope外部调用$scope内部函数,跨js调用非全局函数
scope内部函数定义 //定位 $scope.LocateByPoint = function (x,y) { if(!x || !y) { window.alert("GPS坐标不存在, ...
-
iframe调用父页面js函数 方法 元素
在一个页面中添加iframe,但是有时需要与父页面进行通信,传递参数. 网上总结有以下方法: 一.iframe标签中 src属性传参 <iframe src="test.jsp?i ...
-
iframe 父框架调用子框架的函数
1.父框架定义: <iframe name="mainframe" id="mainframe" width="100%" scrol ...
-
iframe子父页面函数互相调用
1.iframe子页面调用父页面js函数 子页面调用父页面函数只需要写上window.praent就可以了.比如调用a()函数,就写成: window.parent.a(); 子页面取父页面中的标签 ...
随机推荐
-
用神奇的currentColor制作简洁的颜色动画效果
先上一个兼容性总结图:老版本ie可以直接用复杂方法了,套用某表情包的话: 2016年了,做前端你还考虑兼容IE6?你这简直是自暴自弃! 好了,知道了兼容性,我们可以放心的使用了. 在CSS3中扩展了 ...
-
BZOJ4449 : [Neerc2015]Distance on Triangulation
首先拓扑,每次取出度数为$2$的点,这样可以把所有三角形都找到. 那么建出对偶图,会发现是一棵树. 对这棵树进行点分治,每次取出重心,DFS求出所有在里面的点,然后从重心$3$个点分别做一次BFS. ...
-
网站发布出现“未能找到路径“path\bin\roslyn\csc.exe”....“和拒绝访问的解决办法
最近在2017上新建了一个MVC项目,发布是出现了各种奇怪的问题,其中一个错误是: 未能找到路径“path\bin\roslyn\csc.exe”.... 经过网上搜寻资料发现罪魁祸首就是NUGET里 ...
-
web前端技术学习
$.ajax() ajax数据请求方式,交互,跨域等相关问题 一.请求方式 1.$.ajax() $.ajax({ type:"get",//请求方式“get”和“post” ur ...
-
Statically Linking freeglut
It’s possible statically link freeglut into your applications, instead of dynamically linking agains ...
-
linux学习笔记 4建立用户
一般用法 #useradd mysql 含义 创建 mysql用户 特殊用法 1> #useradd -d /usr/cjh -m cjh 含义:创建cjh用户 产生一个主目录 /usr/cj ...
-
解决Can &#39;t connect to local MySQL server through socket &#39;/tmp/mysql.sock &#39;(2) ";;
解决方案: https://blog.csdn.net/HeatDeath/article/details/79065872 https://blog.csdn.net/hjf161105/artic ...
-
Docker入门与实战讲解
转载自:http://blog.csdn.net/relax_hb/article/details/69668815 简述 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包 ...
-
CSS background-image背景图片相关介绍
这里将会介绍如何通过background-image设置背景图片,以及背景图片的平铺.拉伸.偏移.设置大小等操作. 1. 背景图片样式分类 CSS中设置元素背景图片及其背景图片样式的属性主要以下几个: ...
-
vim命令详解
VIM编辑常用技巧 vim编辑器 简介: vi: Visual Interface,文本编辑器 文本:ASCII, Unicode 文本编辑种类: 行编辑器: sed 全屏编辑器:nano, vi V ...