父子窗口传值-window.open-js

作者:  耕堂 | 本文浏览323次 | 2010年06月23日

父子窗口在页面设计中经常用到,javascript中window.open可以实现,父子窗口之间传递参数变量有时候必须用到,window.open可以轻松实现:
先说父窗口页面(parent.html)
js代码:

function popChild(){
var obj = window;
obj.name = ‘我是父窗口’;
myWindow = window.open(‘open.html’,'Child’,'width=200,height=100′)
myWindow.document.getElementById(‘child’).value = ‘我来自父窗口’;
myWindow.focus();
}

对于子窗口页面(child.html)
js代码:

function parentValue(){
var temp = document.getElementById(‘child’).value;
this.opener.document.getElementById(‘test’).value = temp;//控制父窗口
document.getElementById(‘test2′).value = this.opener.name;//获取父窗口变量(我是父窗口)
}

通过opener来获取父窗口的一些值;
就是这么简单,id为child和test的元素已经省略了,如果测试可以在html页面加上。

p.s. showModalDialog也可以实现父子窗口传值,下一篇再讲。

 右上方更多相关内容/站内搜索-关键词请用空格隔开

  • 标签 :  ,
  • 原文链接 : http://www.gengtang.net/dian-di/window-open-js.html
  • 转载原创文章请注明 : 耕堂-gengtang.net
  •  “父子窗口传值-window.open-js” 有1条评论

    发表留言

    可用HTML标签:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>