JavaScript中window.showModalDialog传递参数

1、在父窗口调用window.showModalDialog ,并得到返回值

 

function uploadFile() {
			var url = "./fileuploadAction.do?method=init";
		    var ret = showModalDialog(url,'',"dialogWidth:470px;DialogHeight=230px;status:no;resizable:yes;help:no;scroll:no");
      		if (ret != null && ret !=""){
				var param = ret.split("-");
			
				var title = param[0].split(";");
				var url   = param[1].split(";");
				alert(title);alert(url);
			}
		}


2、在打开的子窗口添加返回函数,
通过调用window.returnValue将值返回给父窗口

 

<script type="text/javascript">
	function ReturnValue(type)   
     {   
     	if (type == 0){
     		var keys = document.getElementById("filename").value;
			var texts = document.getElementById("fileurl").value;
     		var ret = keys + "-" + texts;
			window.returnValue= ret;
		} else {
			window.returnValue="";
		}
        window.close();
     }
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
		<td style="width:100%;height:20" colspan="2" align="center" nowrap>
			<input type="button" style="width: 45px" class="btn_1" value="确定" onclick="ReturnValue('0')">  
			<input type="button" style="width: 45px" class="btn_1" value="取消" onclick="ReturnValue('1')">
		</td>
  </tr>
</table>


你可能感兴趣的:(JavaScript中window.showModalDialog传递参数)