`
suncf1985
  • 浏览: 27975 次
  • 性别: Icon_minigender_1
  • 来自: 哈尔滨
社区版块
存档分类
最新评论

window.showModalDialog给父窗口赋值

阅读更多

window.open 打开窗口时,可以很轻松的取得其父窗口。项目中需要用 showModalDialog打开窗口,想要取得父窗口值,而且还要在 open的基础上修改 为了不让 window.returnValue 所返回的值不是那么烦索,就要想办法如何用showModalDialog 打开的窗口取得其父窗口。何理利用 showModalDialog 传入的参数便可以解决这个问题。

话不多说,看例子:

a.html ---->父窗口

<html>

<head>

<script type="text/javascript" >

function showDialog(){

       // 这里边的东西可以自己着情设置

var param = "dialogWidth:400px;dialogHeight:300px;scroll:no;status:no;resizable:no";

// 打开 b.html,并将当前 window做为参数传入弹出窗口中

return window.showModalDialog("b.html", window , param);

}

</script>

<title></title>

</head>

<body>

<input type="button" value="弹出" onclick="showDialog()"/>

<input type="text" value="父窗口值" name="farValue" id="farValue" />

</body>

 

b.html ---->子窗口

<html>

<head>

<script type="text/javascript" >

function getParValues(){ 

       // 接收父窗口传过的 window对象.

var parWin= window.dialogArguments;

parWin.document.getElementById("farValue").value = "子窗口改变的值";

}

</script>

<title></title>

</head>

<body>

<input type="button" value="改变父窗口值"  onclick="getParValues()" />

</body>

 

这里有几个需要注意:showModalDialog,在传参数的时候,可以是任意类型。以上例子中是以父窗口的window对象为参数传过去的.你在子窗口取到了父的window对象,你就可以在子窗口里为所欲为了。呵呵

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics