父页面代码
function alert_page(id)
{
var k = window.showModalDialog("PicAdd.aspx?uid=<%=uid%>&filetype=1&temp=<%=temp %>",window,"dialogWidth:500px;dialogHeight:500px;help:no;maximize:no;minimize:no;scroll:aotu;status:no;resizable:no");
alert(k);
if(k!=null) document.getElementById(id).src=k;
}子页面代码function retval()
{
window.returnValue="asdasdasd"; //设置了返回值
window.close();//该页关闭时,该值才会返回
}结果alert(k) 为undefined 愁死我了 到底是怎么回事啊 高手解答!
function alert_page(id)
{
var k = window.showModalDialog("PicAdd.aspx?uid=<%=uid%>&filetype=1&temp=<%=temp %>",window,"dialogWidth:500px;dialogHeight:500px;help:no;maximize:no;minimize:no;scroll:aotu;status:no;resizable:no");
alert(k);
if(k!=null) document.getElementById(id).src=k;
}子页面代码function retval()
{
window.returnValue="asdasdasd"; //设置了返回值
window.close();//该页关闭时,该值才会返回
}结果alert(k) 为undefined 愁死我了 到底是怎么回事啊 高手解答!
<script>
function retval(e){
window.returnValue="asdasdasd";
}
</script><body onbeforeunload='retval(event);'>
弱弱的问一句,你是不是忘记写body的事件了
<body onunload='retval()'>
<body>
<script>
function alert_page(id)
{
var k = window.showModalDialog("b.html",window,"dialogWidth:500px;dialogHeight:500px;help:no;maximize:no;minimize:no;scroll:aotu;status:no;resizable:no"); if(k){ document.getElementById(id).innerHTML=k;}
else{ alert(k);}
}
</script>
<input type='button' value='click me' onclick='alert_page("div")' />
<div id='div'></div>
</body>
</html>
b.html<html>
<body>
<script>
function retval()
{
window.returnValue="asdasdasd"; //设置了返回值
window.close();//该页关闭时,该值才会返回
}</script>
<input type='button' value='close' onclick='retval();' />
</body>
</html>
returnValue 在这里是正确的
你确定关闭的时候触发了那个方法了。如果是直接按窗口右上角自带的关闭的话,不会触发你那个方法的。
我有一個類似的可供參考!我的是從子頁面的下拉框返回值到父頁面的一個文本框裡.
父頁面代碼:
<script type="text/javascript" language="javascript">
function doInput()
{
if(document.getElementById("txtUnit").value!="")
{
var unitid = document.getElementById("txtUnit").value;
var win = window.showModalDialog("tmep/getLot.aspx?unitid="+unitid,window,"dialogWidth=300px;dialogHeight=100px;center=yes;status=no");
if(win != null)
{
document.getElementById("txtLot").value = win;
}
}
}
</script><script language="javascript" type="text/javascript" >
function doPassToParent()
{ window.returnValue = document.getElementById("DropDownList1").value;
window.close();
}
</script>
<body>
<form id="form1" runat="server">
<center>
<div>
<table cellpadding="0" cellspacing="0" border = "1">
<tr>
<td>工單:</td>
<td><asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList></td>
</tr>
<tr>
<td colspan="2"><a href="javascript:doPassToParent();">確定</a> <a href="javascript:window.close();">關閉</a></td>
</tr>
</table>
</div>
</center>
</form>
</body>