javascript使用window.opener在两个页面之间传递值
1、使用第一个页面打开第二个页面,通过第二个页面传递值给第一个页面
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<form name="form1" action="test.htm" method="post">
客户ID:<input type="text" name="cid" value="" id="cid"><br/>
客户名称:<input type="text" name="cname" value="" id="cname"><br/>
<input type="button" name="ok" value="请选择客户" onclick="openWin();">
</form>
</body>
<script type="text/javascript">
/*
* window.open(sURL,sName,sFeatrues);
* sURL:要打开文件的URL地址
* sName:指定打开窗口的名字:_self当前窗口 _blank:在新窗口打开
* sFeatures:装饰
*/
function openWin() {
window.open("msg.htm","_blank","height=200,width=200,status=yes,toolbar=no,menubar=no");
}
function setValue(cid,cname) {
document.getElementById("cid").value = cid;
document.getElementById("cname").value = cname;
}
</script>
</html>
2、第二个页面获取第一个页面的对象,并调用第一个页面的方法,将第一个页面所需要的值传递给第一个页面
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
function viewData(cid ,cname) {
//获取通过showModalDialog传过来的window对象
var sdata = window.opener;
//设置第一个页面的属性值
// sdata.document.getElementById("cid").value = cid;
// sdata.document.getElementById("cname").value = cname;
sdata.setValue(cid,cname);
//关闭Dialog窗口
window.close();
}
</script>
</head>
<body>
<table border="1">
<tr>
<td>操作</td>
<td>客户ID</td>
<td>客户名称</td>
</tr>
<tr>
<td><button onclick="viewData('001','深圳华为')">选择</button></td>
<td>001</td>
<td>深圳华为</td>
</tr>
<tr>
<td><button onclick="viewData('002','用友软件')">选择</button></td>
<td>002</td>
<td>用友软件</td>
</tr>
</table>
</body>
</html>
分享到:
相关推荐
比如点击了a.htm上的一个链接而打开了b.htm,然后我们打算在b.htm上输入一个值然后赋予a.htm上的一个id为“name”的textbox中,就可以写为: window.opener.document.getElementById(“name”).value = “输入的数据...
可以看一看啊 博文链接:https://bageer707.iteye.com/blog/74458
2个页面,加了注释,很清晰。
对window.open进行封装, 使其更好用, 且更兼容, 很多人说window.open不兼容,其实不是, 因为不能直接执行, 必须通过用户手动触发才行;看代码: 代码如下 var openWindow = function(url, options) { var str = ""; ...
2> 父窗口与子窗口传递值的方式也有所不同,在子窗口中操作父窗口也语法也不同,分别为var parentObjs = window.dialogArguments;opener.parentObj.elementObj.arrtr = 'str'; 3> IE与FireFox对两个弹出窗口在...
window.opener=null;window.close(),只支持IE6不支持IE7的问题 打开新窗口并且关闭本窗口不弹出要关闭窗口前的提示function openWin(){window.open(‘login.jsp’,”,’fullscreen=yes,menubar=no,resizable=no’);...
window.opener,是通过window.open打开子窗体的父窗体的引用。 比如在父窗体parentForm里面,通过window.open(“subForm.html”),那么在subform.html中window.opener就代表parentForm。既然在子窗体中能够拿到父窗体...
在jsp页面通过javascript,调用opener方法在页面之间传递参数,子页面将参数返回给父页面
window.opener.location.href = window.opener.location.href 刷新以winodw.showModelDialog()方法打开的窗口 window.parent.dialogArguments.document.execCommand('Refresh'); 或 Response.Write("<script>...
JS代码: window.open(); 而当支付成功后,需要关闭支付平台支付成功界面,并在客户端加载客户端支付成功页面,JS代码: window.opener.location.href=url;window.close();
如果网页 A 可以发送信息到网页 B,反之也然,而不必动用请求/应答模式,该是一件多么惬意的事儿。可以轻松地实现聊天不是吗?
(“#父窗口元素ID”,window.parent.document); 对应javascript版本为window.parent.document.getElementByIdx_x(“父窗口元素ID”);取父窗口的元素方法:$(selector, ...$(selector, window.opener.document);$(s
40.数学函数:Math.PI(返回圆周率),Math.SQRT2(返回开方),Math.max(value1,value2)返回两个数中的最在 值,Math.pow(value1,10)返回value1的十次方,Math.round(value1)四舍五入函数,Math.floor (Math.random()*(n+1))...
熟练掌握window对象的status、location、name、self、opener属性的使用 Window对象是客户端javascript最高层对象之一,只要打开浏览器窗口,不管该窗口中是否有打开的网页,当遇到BODY、FRAMESET或FRAME元素时,...