首页 > 其他分享 >window.parent与window.opener的区别

window.parent与window.opener的区别

时间:2023-06-15 12:07:08浏览次数:49  
标签:parentWin parent small window opener var 页面


window.parent与window.opener的区别 javascript调用主窗口方法


2007-11-30 13:42






在这里总结一下,javascript调用父窗口(父页面)的方法。

1:   window.parent 是iframe页面调用父页面对象

举例:

a.html        

<html>        
<head><title>父页面</title></head>        
<body>        
<form name="form1" id="form1">        

<input type="text" name="username" id="username"/>        

</form>        
<iframe src="b.html" width=100%></iframe>        
</body>        
</html>



如果我们需要在b.htm中要对a.htm中的username文本框赋值,就如很多上传功能,上传功能页在Ifrmae中,上传成功后把上传后的路径放入父页面的文本框中

我们应该在b.html中写

<script type="text/javascript">        
var _parentWin = window.parent ;        
_parentWin.form1.username.value = "xxxx" ;        
</script>



实例地址:   http://www.cnspry.cn/blog/attachments/window.parent实例/a.html
源码:
1.a<html>

<head><title>主页面</title></head>        
<body>        
<form name="form1" id="form1">       

        <input type="text" name="username" id="username"/>       


        </form>        
<iframe src="b.html" width=100%></iframe>        
</body>        
</html>        
1.b<html>        
<head><title></title>        
<script type="text/javascript">       

        function UpdateParent()        
{        

var _parentWin = window.parent ;        

_parentWin.form1.username.value = "xxxx" ;        

}         
</script>        
</head>        
<body>        
<form name="form1" id="form1">        
<p>  </p>        
<p align="center">        
    <input type="button" name="button" id="button" value="更新主页面的UserName内容" onClick="UpdateParent();">        
</p>        
<p>  </p>        
</form>       

        </body>        
</html>


2:   window.opener 是window.open 打开的子页面调用父页面对象

实例地址:   http://www.cnspry.cn/blog/attachments/window.opener实例/a.html
源码:


2.a<html>        
<head>        
<title>主页面</title>        
<script type="text/javascript">        
function openSubWin()        
{       

        var _width = 300 ;        

var _height = 200 ;       

        var _left = (screen.width - _width) / 2 ;        
          
var _top = (screen.height - _height) / 2 ;        
          
window.open("b.html",null,        
"height=" + _height + ",width=" + _width + ",status=no,toolbar=no,menubar=no,location=no,resizable=yes,left=" + _left + ",top=" + _top);       


}        
</script>        
</head>        
<body>       

        <form name="form1" id="form1">       


        <input type="text" name="username" id="username"/>       


        <input type="button" value="弹出子页面" onClick="openSubWin();">       


        </form>       


        </body>        
</html>        

2.b<html>        
<head>        
<title>子页面</title>        
<script type="text/javascript">       

        function UpdateParent()        
{        

var _parentWin = window.opener ;        

_parentWin.form1.username.value = "xxxx" ;        

}         
</script>        
</head>        
<body>        
<form name="form1" id="form1">        
<p>  </p>        
<p align="center">        
    <input type="button" name="button" id="button" value="更新主页面的UserName内容" onClick="UpdateParent();">        
</p>        
<p>  </p>        
</form>


</body>
</html><%
Call FunMsg("upload_pic.asp?Send=OK&FileName="&SFileName&"&FileName_small="&Sfilename_small,"文件上传成功!")
   
Dim Send,StrBody
Send=Request.QueryString("Send")
FileName=Request.QueryString("FileName")
FileName_small=request.QueryString("FileName_small")
if Send="OK" And FileName<>"" And FileName_small<>"" then
StrBody="onLoad=setOpener('"&FileName&"','"&FileName_small&"')"
end if<script type="text/javascript">
function setOpener(index,index_small) {
   window.opener.Images(index,index_small);
   window.close();
}
</script><body leftmargin="0" topmargin="0" <%=StrBody%>>
<script type="text/javascript">
function Images(catName,catName_small){
document.form.P_Pic.value=catName;
document.form.P_smallPic.value=catName_small;
document.form.P_PicB.src="../info/Pic/"+catName;
}
</script><input name="P_Pic" type="hidden" id="P_Pic" Value="<%=pRs("P_Pic")%>">
<input name="P_smallPic" type="hidden" id="P_smallPic" Value="<%=pRs("P_smallPic")%>">%>



标签:parentWin,parent,small,window,opener,var,页面
From: https://blog.51cto.com/u_16065168/6486029

相关文章

  • 为什么AirtestIDE的selenium Window突然无法检索控件了?
    1.前言最近有很多朋友跟我们反馈,为什么1.2.15版本的IDE没办法做网页元素检索了,是不是我们不支持selenium了之类的。测试后发现,目前版本确实存在这个问题,原因是Chrome113.0.5672.127(最新)版本过高,AirtestIDE1.2.15暂未兼容。2.问题表现1)无法检索控件我们尝试使用Airtest1.2......
  • [-002-]-Python3+Unittest+Uiautomation Windows桌面App UI自动化之鼠标操作
    1、单击鼠标左键Click(x:int,y:int,waitTime:float=OPERATION_WAIT_TIME)模拟鼠标在点x,y的点击。OPERATION_WAIT_TIME默认为0.5即等待时间默认为0.5秒2、单击鼠标中键MiddleClick(x:int,y:int,waitTime:float=OPERATION_WAIT_TIME)模拟鼠标在点x,y......
  • CentOS搭建NFS服务、windows挂载权限问题; NFS读写缓慢调优
    CentOS搭建NFS服务、windows挂载权限问题CentOS和统信UOS(与ubuntu一样)命令不一样,但操作大同小异,参考如下:https://blog.csdn.net/wangzongyu/article/details/127009158 windows读写linux搭建的NFS内文件是比较慢,调优:https://blog.csdn.net/yysalad/article/details/11736623......
  • DataX在Windows上实现Mysql到Mysql同步数据以及配置多个job/多个表同步定时执行bat
    场景DataX-阿里开源离线同步工具在Windows上实现Sqlserver到Mysql全量同步和增量同步:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/130330353DataX-在Windows上实现postgresql同步数据到mysql:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/130......
  • windows php7、PHPStudy(小皮)配置oracle扩展
    一、php配置oci扩展1.访问链接下载对应oracle版本的即时客户端(OracleInstantClient)https://www.oracle.com/database/technologies/instant-client/winx64-64-downloads.html  2.解压下载文件,将下面两个文件放入php目录下   3.访问链接https://windows.php.net/down......
  • windows 11安装telnet教程
    很多时候我们需要使用telnet命令,ping端口通不通,所以得先安装下系统自带的telnet工具。telnet工具日常还是非常好用的。如果未安装则会提示:'telnet'不是内部或外部命令,也不是可运行的程序或批处理文件。 下面介绍两种方式,一个是老的操作方式,在"控制面板"中安装,另一个是在win......
  • Windows安装多版本MySQL(命令行)
    注意:电脑上可以多个数据库版本共存,但是在初次安装执行mysqld-installmysql的时候需要将mysql替换为唯一的名字,并且环境变量只能配置一个1.windows中下载指定版本官网下载命令行版本:https://dev.mysql.com/downloads/mysql/解压到指定位置编写my.ini文件[mysqld]#设......
  • Windows server 2022 Datacenter 21h2 20230517 20348.1787
    Windowsserver2022Datacenter21h22023051720348.1787slmgr.vbs-dlv......
  • windows/mac/linux jupyter notebook 切换默认环境
    很多人跟我讲jupyternotebook都是运行在默认环境下,不好更改,但是我又喜欢创建虚拟环境,要切换到虚拟环境下运行,以下几招即可。终端下进行,windows版本/mac版本基本一样。1.查看所有环境  condaenvlist2.激活你要用的环境,activateXXX,我的虚拟环境为luo3.condainstallipyk......
  • Windows Terminal 中配置代理
    WindowsTerminal中配置代理cmd中临时设置代理:sethttp_proxy=http://127.0.0.1:10809sethttps_proxy=http://127.0.0.1:10809取消代理:sethttp_proxy=sethttps_proxy=‍若要长久生效,在系统环境变量中添加:http_proxy和https_proxy两个系统变量,值均为:http://127.......