LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
版主

window.opener与window.parent的区别

tercel
2010年8月6日 10:24 本文热度 4560
[p] 我们如果要用到iframe的值传到另一框架就要用到window.opener.document.getelementbyid(name).value = uvalue;这种形式哦。 [br]window.parent能获取一个框架的父窗口或父框架。顶层窗口的parent引用的是它本身。 [br][br]可以用这一点特性来判断这个窗口是否是顶层窗口。如: [br][br]code [br]function istopwindow( win ) [br]{ [br] if( win.parent == win ) return true; [br] else return false; [br]} [br]window.opener引用的是window.open打开的页面的父页面。 [br][br][br]opener即谁打开我的,比如a页面利用window.open弹出了b页面窗口,那么a页面所在窗口就是b页面的opener,在b页面通过opener对象可以访问a页面。 [br]parent表示父窗口,比如一个a页面利用iframe或frame调用b页面,那么a页面所在窗口就是b页面的parent。 [br]在js中,window.opener只是对弹出窗口的母窗口的一个引用。比如: [br][br]a.html中,通过点击按钮等方式window.open出一个新的窗口b.html。那么在b.html中,就可以通过 window.opener(省略写为opener)来引用a.html,包括a.html的document等对象,操作a.html的内容。假如这个引用失败,那么将返回null。所以在调用opener的对象前,要先判断对象是否为null,否则会出现“对象为空或者不存在”的js错误。 [br][br]window.opener 返回的是创建当前窗口的那个窗口的引用,比如点击了a.htm上的一个链接而打开了b.htm,然后我们打算在b.htm上输入一个值然后赋予a.htm上的一个id为“name”的textbox中,就可以写为: [br]window.opener.document.getelementbyid("name").value = "输入的数据"; [br][br][br][br][br]====================================================================== [br][br][br][br]window.parent.location.reload() [br]让打开这个窗口的父窗口刷新,然后本子窗口关闭! [br][br]window.parent.hidethisdiv() [br]应该是让打开这个窗口的父窗口的某个div影藏 [br][br]javascript:history.back() [br]就是后退啊!和浏览器里面的后退按钮一样!javascript:history.back(-1)就是后退一页 [br][br][br][br]========================================= [br][br][br][br]前边用window.opener=null来完成了窗口的无提示自动关闭.简单查了一下,window.opener是js中window的一个属性,它返回的是打开当前窗口的窗口对象.如果窗口a弹出一个窗口b,那么在b中window.opener就是窗口对象a. [br]这是javascript参考手册里对于opener的描述 [br][br][br] when a source document opens a destination window by calling the open method, the opener property specifies the window of the source document. evaluate the opener property from the destination window. [br] this property persists across document unload in the opened window. [br] you can change the opener property at any time. [br] you may use window.open to open a new window and then use window.open on that window to open another window,and so on. in this way, you can end up with a chain of opened windows, each of which has an opener property pointing to the window that opened it. [br] communicator allows a maximum of 100 windows to be around at once.if you open window2 from window1 and then are done with window1, be sure to set the opener property of window2 to null. this allows javascript to garbage collect window1. if you do not set the opener property to null, the window1 object remains, even though it's no longer really needed. [br][br]我大概翻译一下 [br]当一个窗口用open方法打开了一个新窗口的时候,opener属性就生效了,直到被打开的窗口关闭时失效. [br]你可以通过opener在被打开的窗口中对父窗口进行一系列操作. [br]你可以在一个窗口中打开一个新窗口,新窗口又打开另外一个新窗口,新窗口又打开另外一个新窗口.....最后得到的是一串新窗口:em215:,然而每一个窗口的opener属性都指向打开它的那个窗口. [br]设计者最多允许打开100个这样的窗口.当你通过open打开了一个新窗口后,确保在新窗口中将opener属性设置为null(空).如果不这样的话,会使浏览器持续的保留每个opener的值,直至资源耗尽. [br][br]js参考手册还给出了几个例子,我把我理解的部分演示一下~ [br][br]首先建立1.htm,它用open方法打开2.htm,代码如下 [br][br][br]
Copyright 2010-2024 ClickSun All Rights Reserved