`
chinrui
  • 浏览: 94417 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

javascript使用window.opener在两个页面之间传递值

阅读更多
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>

分享到:
评论

相关推荐

    javascript window.opener的用法分析

    比如点击了a.htm上的一个链接而打开了b.htm,然后我们打算在b.htm上输入一个值然后赋予a.htm上的一个id为“name”的textbox中,就可以写为: window.opener.document.getElementById(“name”).value = “输入的数据...

    通过window.opener控制父窗体

    可以看一看啊 博文链接:https://bageer707.iteye.com/blog/74458

    字符串 window.open() window.opener window.name window对象等的总结

    2个页面,加了注释,很清晰。

    Javascript中封装window.open解决不兼容问题

    对window.open进行封装, 使其更好用, 且更兼容, 很多人说window.open不兼容,其实不是, 因为不能直接执行, 必须通过用户手动触发才行;看代码: 代码如下 var openWindow = function(url, options) { var str = ""; ...

    showModalDialog open弹出子窗口操作parent、opener父窗口及跨域处理

    2&gt; 父窗口与子窗口传递值的方式也有所不同,在子窗口中操作父窗口也语法也不同,分别为var parentObjs = window.dialogArguments;opener.parentObj.elementObj.arrtr = 'str'; 3&gt; IE与FireFox对两个弹出窗口在...

    解决window.opener=null;window.close(),只支持IE6不支持IE7,IE8的问题

    window.opener=null;window.close(),只支持IE6不支持IE7的问题 打开新窗口并且关闭本窗口不弹出要关闭窗口前的提示function openWin(){window.open(‘login.jsp’,”,’fullscreen=yes,menubar=no,resizable=no’);...

    window.opener用法和用途实例介绍

    window.opener,是通过window.open打开子窗体的父窗体的引用。 比如在父窗体parentForm里面,通过window.open(“subForm.html”),那么在subform.html中window.opener就代表parentForm。既然在子窗体中能够拿到父窗体...

    opener实例页面之间传递参数

    在jsp页面通过javascript,调用opener方法在页面之间传递参数,子页面将参数返回给父页面

    jsp 刷新父页面

    window.opener.location.href = window.opener.location.href 刷新以winodw.showModelDialog()方法打开的窗口 window.parent.dialogArguments.document.execCommand('Refresh'); 或 Response.Write("&lt;script&gt;...

    JS window.opener返回父页面的应用

    JS代码: window.open(); 而当支付成功后,需要关闭支付平台支付成功界面,并在客户端加载客户端支付成功页面,JS代码: window.opener.location.href=url;window.close();

    用window.open,opener实现网页间通信

    如果网页 A 可以发送信息到网页 B,反之也然,而不必动用请求/应答模式,该是一件多么惬意的事儿。可以轻松地实现聊天不是吗?

    解析jquery获取父窗口的元素

    (“#父窗口元素ID”,window.parent.document); 对应javascript版本为window.parent.document.getElementByIdx_x(“父窗口元素ID”);取父窗口的元素方法:$(selector, ...$(selector, window.opener.document);$(s

    javascript函数的解释

    40.数学函数:Math.PI(返回圆周率),Math.SQRT2(返回开方),Math.max(value1,value2)返回两个数中的最在 值,Math.pow(value1,10)返回value1的十次方,Math.round(value1)四舍五入函数,Math.floor (Math.random()*(n+1))...

    javascript常用对象梳理

    熟练掌握window对象的status、location、name、self、opener属性的使用 Window对象是客户端javascript最高层对象之一,只要打开浏览器窗口,不管该窗口中是否有打开的网页,当遇到BODY、FRAMESET或FRAME元素时,...

Global site tag (gtag.js) - Google Analytics