`

window.parent与window.opener的区…

 
阅读更多

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

举例: a.html

<html>
<head><title>A</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.html中要对a.html中的username文本框赋值(就如很多上传功能,上传功能页在ifrmae中,上传成功后把上传后的路径放入父页面的文本框中),我们应该在b.html中写:

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

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

opener:对打开当前窗口的window对象的引用,如果当前窗口被用户打开,则它的值为null。

self代表自身窗口,opener代表打开自身的那个窗口,比如窗口a.html打开窗口b.html。如果靠window.open方法,则对于窗口b.html,self代表b.html自己,而opener代表窗口a.html。

举例:a.html

<input type="text" name="username"id="username"/>
<aonclick="window.open(this.href,'','resizable=yes,width=800,height=600,status');return false"href="b.html">B</a>

如果需要在b.html中对a.html中的表单元素赋值,我们应该在b.html中这么写

<ahref="javascript:try{window.opener.document.getElementByIdx_x('username').contentWindow.
frames[0].document.getElementsByTagName_r('body')[0].innerHTML+='xxx'}catch(e){};window.close();">插入</a>

在后面用window.close关闭b.html



"window.location.href"、"location.href" 当前页面跳转
"parent.location.href":上一级父页面跳转
"top.location.href":顶级页面跳转


连接的时候target的用法了:
_blank:重新打开一个窗口
_parent:父窗口执行重定向
_self:自身页面重定向
_top:第一个父窗口重定向

内嵌iframe:
window、self、window.self 当前页面对象。
window.parent 是iframe页面调用父页面对象。
window.top 顶层页面对象。
oepn:
window.open 返回的是子页面对象
window.opener 在子页面中使用父类对象

contentWindow属性是指指定的frame或者iframe所在的window对象

在IE中iframe或者frame的contentWindow属性可以省略,但在Firefox中如果要对iframe对象进行编辑则

必须指定contentWindow属性。

function EnableEdit()
{
var editor;
editor = document.getElementById("HtmlEdit").contentWindow;
// 针对IE浏览器, make it editable
editor.document.designMode = 'On';
editor.document.contentEditable = true;
// For compatible with FireFox, it should open and write something to make it work
editor.document.open();
editor.document.writeln('<html><head>');
editor.document.writeln('<style>body {background: white;font-size:9pt;margin: 2px; padding: 0px;}</style>');
editor.document.writeln('</head><body></body></html>');
editor.document.close();

}

<iframe ID="HtmlEdit" MARGINHEIGHT="1" MARGINWIDTH="1" width="100%" height="312">
</iframe>

<html>
<body>
<script>
var ifr = document.createElement("iframe");
document.body.appendChild(ifr);
var ifrdoc = ifr.contentWindow.document;
var s = fixingHTB.innerHTML; //进入可编辑模式前存好
ifrdoc.designMode = "on"; //文档进入可编辑模式
ifrdoc.open(); //打开流
ifrdoc.write(s);
ifrdoc.close(); //关闭流
ifrdoc.designMode ="off"; //文档进入非可编辑模式
</script>
</body>


var frames=window.top.window.document.getElementById("rightframe");
frames.contentWindow.TshowMsg(msg,'');
分享到:
评论

相关推荐

    showModalDialog open弹出子窗口操作parent、opener父窗口及跨域处理

    opener.parentObj.elementObj.arrtr = 'str'; 3&gt; IE与FireFox对两个弹出窗口在跨域时的解析也有不同:通过window.dialogArguments操作父窗口时,在IE下不需要指定document.domain而在FireFox下则正好相反需要指定...

    javascript window.opener的用法分析

    window.opener 的用法 window.opener 返回的是创建当前窗口的那个窗口的引用,比如点击了a.htm上的一个链接而打开了b.htm,然后我们打算在b.htm上输入一个值然后赋予a.htm上的一个id为“name”的... opener.parent

    解析jquery获取父窗口的元素

    (“#父窗口元素ID”,window.parent.document); 对应javascript版本为window.parent.document.getElementByIdx_x(“父窗口元素ID”);取父窗口的元素方法:$(selector, ...$(selector, window.opener.document);$(s

    jsp 刷新父页面

    window.opener.location.href = window.opener.location.href 刷新以winodw.showModelDialog()方法打开的窗口 window.parent.dialogArguments.document.execCommand('Refresh'); 或 Response.Write("&lt;script&gt;...

    JS window对象的top、parent、opener含义介绍

    例如:A页面通过window.open()方法弹出了B页面,在B页面中就可以通过opener来引用A页面,这样就可以通过这个对象来对A页面进行操作。 3.parentparent用于在iframe,frame中生成的子页面中访问父页面的对象。例如:A...

    javascript关于open.window子页面执行完成后刷新父页面的问题分析

    本文实例分析了javascript关于open.window子页面执行完成后刷新父页面的方法。分享给大家供大家参考。具体分析如下: 主页面: &lt;input id=btnAdd type=button onclick=openWin(); value=添加 /&gt; 在js中有如下...

    javascript提示类

    某页面中button按钮事件写代码如下: ... Response.Write("&lt;script&gt;window.open('" + Str1 + "','_blank');window.showModalDialog('close.htm');...&lt;body onload="window.parent.opener=null;window.close();"&gt; &lt;/html&gt;

    JS子父窗口互相操作取值赋值的方法介绍

    $(“#父窗口元素ID”,window.parent.document); 对应javascript版本为window.parent.document.getElementByIdx_x(“父窗口元素ID”); 取父窗口的元素方法:$(selector, window...$(selector, window.opener.document)

    firefox下frameset取不到值的解决方法

     js操作frame详细解说,window.opener和window.parent的区别 frame框架里的页面要改其他同框架下的页面或父框架的页面就用parent window.opener引用的是window.open打开的页面的父页面。 window.frames对象可以引用...

    js AspxButton的客户端操作

    javascript调用父窗口(父页面)的方法 window.parent与window.opener的区别 javascript调用主窗口方法 1: window.parent 是iframe页面调用父页面对象 2: window.opener 是window.open 打开的子页面调用父页面对象...

    子窗体与父窗体传值示例js代码

    代码如下: //返回值给父窗体 function returnParent(value) {//获取子窗体返回值 var parent = window.dialogArguments;... //关闭子页面 } //window.opener.document.getElementById(“ActivityPic”);

    js中opener与parent的区别详细解析

    opener即谁打开我的,比如A页面利用window.open弹出了B页面窗口,那么A页面所在窗口就是B页面的opener,在B页面通过opener对象可以访问A页面。 parent表示父窗口,比如一个A页面利用iframe或frame调用B页面,那么A...

    javascript常用对象梳理

    熟练掌握window对象的status、location、name、self、opener属性的使用 Window对象是客户端javascript最高层对象之一,只要打开浏览器窗口,不管该窗口中是否有打开的网页,当遇到BODY、FRAMESET或FRAME元素时,...

    JS刷新父页面 父窗口

    // 刷新父页面。此段代码放在被弹出的页面 function refreshOpener() { ... if (win.opener) win.opener.location.reload();//或parent.location.reload(); } catch (ex) { } } ......................

    js调用父框架函数与弹窗调用父页面函数的简单方法

    window.opener引用的是window.open打开的页面的父页面。 window.frames对象可以引用iframe里的页面,也可以引用frameset里的页面. 可以这样 window.frames[0].document.getElementById(‘xx'); 可以这样 window....

    107个常用javascript语句

    72.JS中指定当前打开窗口的父窗口:window.opener,支持opener.opener...的多重继续. 73.JS中的self指的是当前的窗口 74.JS中状態栏显示內容:window.status="內容" 75.JS中的top指的是框架集中最顶层的框架 76.JS中...

    javascript函数的解释

    72.JS中指定当前打开窗口的父窗口:window.opener,支持opener.opener...的多重继续. 73.JS中的self指的是当前的窗口 74.JS中状态栏显示内容:window.status="内容" 75.JS中的top指的是框架集中最顶层的框架 76.JS中...

    js 无提示关闭浏览器页面的代码

    blank,在新窗口显示目标网页 _self,在当前窗口显示目标网页 _parent,框架网页中当前整个窗口位置显示目标网页 _top,框架网页中在上部窗口中显示目标网页 软件开发网自己用的函数 代码如下:function closeWindow...

    百度点击父页面底部广告效果

    百度点击父页面底部广告效果 window.opener.parent.location= "http://www.juyaonet.com/baidu_bp.html?key=哈尔滨巨耀网络科技有限公司"; &lt;/script&gt;

Global site tag (gtag.js) - Google Analytics