`
天梯梦
  • 浏览: 13632605 次
  • 性别: Icon_minigender_2
  • 来自: 洛杉矶
社区版块
存档分类
最新评论

javascript 弹出窗口返回值 (open, showModalDialog)

阅读更多

test.php

 

<form name="form1" method="post" action="">
	<a href="javascript:void(null)" class="add" onClick="open('demo.php','','resizable=1,scrollbars=1,status=no,toolbar=no,menu=no,width=500,height=400,left=150,top=50')">增加</a>
	<input type="text" name="text1">
</form>
 

demo.php

 

<script language="javascript" type="text/javascript">
	function returnValue()
	{
		window.opener.document.all.text1.value=document.getElementById("returnText").value;
		window.close();
	}
</script>
<p>
    <input type="button" name="Submit" value="提交" onclick="returnValue();">
    <input name="returnText" type="text" id="returnText">
</p>
 

 

补充:window.opener 的用法



window.opener 的用法在一般的用法中,只是用来解决关闭窗口时不提示弹出窗口, 而对它更深层的了解一般比较少。其 实 window.opener是指调用window.open方法的窗口。在工作中主要是用来解决部分提交的。这种跨页操作对工作是非常有帮助的。


如果你在主窗口打开了一个页面,并且希望主窗口刷新就用这个,打开页面的window.opener就相当于主窗口的window。


主窗口的刷新你可以用 window.opener.location.reload();


如果你要提交主窗口: 你可以改成这样 window.opener.yourformname.submit()

 

 

实例2:open

 

test.php

 

<script  language="JavaScript">
	var a = '';  
    window.open("test3.php");  
	function button1_onclick()   {  
		alert(a);  
	}  
</script>  

<input type="button" id="button1" name="button1" value="Button" onclick="return button1_onclick()" />
 

 

test3.php

 

<script  language="JavaScript">
    function   sendTo()  
    {  
        window.opener.a='test';   
		window.close();
    }  
</script>  

<form id="form1" name="form1">  
	<input type="button" id="button1" name="button1" value="返回" onclick="sendTo()" />  
</form>   
 

 

实例3:showModalDialog

 

test.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>弹出窗口</title>
<script  language="JavaScript">
function pop()
{
	var arr = showModalDialog("test5.php", "", "dialogWidth:400; dialogHeight:400; status:0");
	if (arr != null){
		alert('您点击了:' + arr);
	}
}
</script>
</head>
<body>

<div align="center"><input type="button" value="点我弹出窗口" onclick="pop()" /></div>

</body>
</html>

 

test5.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>弹出窗口</title>
<script>
	function check(s){
		window.returnValue = s;
		window.opener=null;
		window.close();
	}
</script>
</head>

<body>
	<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
	  <tr align="center"> 
		<td>点击链接:</td>
		<td><a href="#" onclick="check('Share JavaScript')">Share JavaScript</a></td>
		<td><a href="#" onclick="check('share.com')">share.com</a></td>
	</tr>
	</table>
</body>
</html>

 

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics