分两种弹出方式 window.showModalDialog 和 windows.open window.showModalDialog js代码 var rv = window.showModalDialog("Query_frame.aspx?key=" + key, "", "dialogWidth=500px;dialogHeight=230px;status=no;scroll=no;help=no");
rv就是返回的字串,你可以把rv换成TextBox的value
在弹出的窗口这样 window.returnValue='返回的字符串';window.close(); windows.open 需要使用 window.opener window.opener 返回的是创建当前窗口的那个窗口的引用,比如点击了a.htm上的一个链接而打开了b.htm,然后我们打算在b.htm上输入一个值然后赋予a.htm上的一个id为“name”的textbox中,就可以写为:window.opener.document.getElementById("name").value = "输入的数据"; <html> <body> <form name=form1> <input type=text name=inpu > <input type=button onclick="javascript:window.open('back2opener.html?toname=opener.form1.inpu');"> </form> </body> </html>
-------------------------------- back2opener.html -------------------------------- <html> <body> <form name=form1> <input type=text name=inpu >
<a class=under href=# onclick="{opener.document.form1.inpu.value+='孙超,';}">添加</a> </form> </body> </html> 在JS中,window.opener只是对弹出窗口的母窗口的一个引用。比如:a.html中,通过点击按钮等方式window.open出一个新的窗口b.html。那么在b.html中,就可以通过window.opener(省略写为opener)来引用a.html,包括a.html的document等对象,操作a.html的内容。 假如这个引用失败,那么将返回null。所以在调用opener的对象前,要先判断对象是否为null,否则会出现“对象为空或者不存在”的JS错误。
|