程序实现网页弹出页面输入值并返回父窗口:方便大家测试。
测试window.showModalDialog()方法传递值的子页面和window.open()方法传递值的子页面
1 TestTransferValu.html
2 showmodal.html
3 TestOpen.html
建议使用open()方法,因为showModdalDialog()方法在FireFox下不支持。
参考地址: http://www.webjx.com/htmldata/2005-08-02/1122939471.html
测试window.showModalDialog()方法传递值的子页面和window.open()方法传递值的子页面
1 TestTransferValu.html
<
HTML
>
< HEAD >
< title > Test TransferValue </ title >
< meta name ="GENERATOR" Content ="Microsoft Visual Studio .NET 7.1" >
< meta name ="CODE_LANGUAGE" Content ="C#" >
< meta name ="vs_defaultClientScript" content ="JavaScript" >
< meta name ="vs_targetSchema" content =http://schemas.microsoft.com/intellisense/ie5 >
< script >
function TestShowModalDialog()
{
var rv=window.showModalDialog("showmodal.html",window,"dialogWidth=400px;dialogHeight= 300px");
var txtReturnValue=document.getElementById("txtReturnValue");
if (rv==undefined)
{
txtReturnValue.value="没有返回值";
}
else
{
txtReturnValue.value=rv;
}
}
function TestOpen()
{
window.open("TestOpen.html","_blank","height=300,width=400");
}
</ script >
</ HEAD >
< body >
< form id ="frmTestTransferValue" method ="post" runat = "server" >
< INPUT type ="text" id ="txtReturnValue" name = "txtReturnValue" >< br >
< INPUT type ="button" value ="用window.showModalDialog()方法" onclick = "TestShowModalDialog();" >< br >
< INPUT type ="button" value ="用window.open()方法" onclick = "TestOpen();" >< br >
</ form >
</ body >
</ HTML >
< HEAD >
< title > Test TransferValue </ title >
< meta name ="GENERATOR" Content ="Microsoft Visual Studio .NET 7.1" >
< meta name ="CODE_LANGUAGE" Content ="C#" >
< meta name ="vs_defaultClientScript" content ="JavaScript" >
< meta name ="vs_targetSchema" content =http://schemas.microsoft.com/intellisense/ie5 >
< script >
function TestShowModalDialog()
{
var rv=window.showModalDialog("showmodal.html",window,"dialogWidth=400px;dialogHeight= 300px");
var txtReturnValue=document.getElementById("txtReturnValue");
if (rv==undefined)
{
txtReturnValue.value="没有返回值";
}
else
{
txtReturnValue.value=rv;
}
}
function TestOpen()
{
window.open("TestOpen.html","_blank","height=300,width=400");
}
</ script >
</ HEAD >
< body >
< form id ="frmTestTransferValue" method ="post" runat = "server" >
< INPUT type ="text" id ="txtReturnValue" name = "txtReturnValue" >< br >
< INPUT type ="button" value ="用window.showModalDialog()方法" onclick = "TestShowModalDialog();" >< br >
< INPUT type ="button" value ="用window.open()方法" onclick = "TestOpen();" >< br >
</ form >
</ body >
</ HTML >
2 showmodal.html
<
HTML
>
< HEAD >
< title > Test ShowModalDialog </ title >
< meta name ="GENERATOR" Content ="Microsoft Visual Studio .NET 7.1" >
< meta name ="CODE_LANGUAGE" Content ="C#" >
< meta name ="vs_defaultClientScript" content ="JavaScript" >
< meta name ="vs_targetSchema" content =http://schemas.microsoft.com/intellisense/ie5 >
< script >
function CreateReturnValue(closeWindow)
{
var txtReturnValue=document.getElementById("txtReturnValue");
if (txtReturnValue.value=="")
{
window.alert("请输入返回值");
return ;
}
returnValue=txtReturnValue.value;
window.close();
}
</ script >
</ HEAD >
< body >
< form id ="frmTestShowModalDialog" method ="post" runat = "server" >
返回值: < INPUT type ="text" id ="txtReturnValue" name = "txtReturnValue" >
< INPUT type ="button" value ="关闭页面并返回输入的值" onclick = "CreateReturnValue();" >
</ form >
</ body >
</ HTML >
< HEAD >
< title > Test ShowModalDialog </ title >
< meta name ="GENERATOR" Content ="Microsoft Visual Studio .NET 7.1" >
< meta name ="CODE_LANGUAGE" Content ="C#" >
< meta name ="vs_defaultClientScript" content ="JavaScript" >
< meta name ="vs_targetSchema" content =http://schemas.microsoft.com/intellisense/ie5 >
< script >
function CreateReturnValue(closeWindow)
{
var txtReturnValue=document.getElementById("txtReturnValue");
if (txtReturnValue.value=="")
{
window.alert("请输入返回值");
return ;
}
returnValue=txtReturnValue.value;
window.close();
}
</ script >
</ HEAD >
< body >
< form id ="frmTestShowModalDialog" method ="post" runat = "server" >
返回值: < INPUT type ="text" id ="txtReturnValue" name = "txtReturnValue" >
< INPUT type ="button" value ="关闭页面并返回输入的值" onclick = "CreateReturnValue();" >
</ form >
</ body >
</ HTML >
3 TestOpen.html
<
HTML
>
< HEAD >
< title > Test Open </ title >
< meta name ="GENERATOR" Content ="Microsoft Visual Studio .NET 7.1" >
< meta name ="CODE_LANGUAGE" Content ="C#" >
< meta name ="vs_defaultClientScript" content ="JavaScript" >
< meta name ="vs_targetSchema" content =http://schemas.microsoft.com/intellisense/ie5 >
< script >
function CreateReturnValue(closeWindow)
{
var txtReturnValue=document.getElementById("txtReturnValue");
if (txtReturnValue.value=="")
{
window.alert("请输入传递值");
return ;
}
var txtOpenerReturnValue=window.opener.document.getElementById("txtReturnValue");
txtOpenerReturnValue.value=txtReturnValue.value;
window.alert("值已经传给父窗体");
if (closeWindow)
{
window.opener=null;
window.close();
}
}
</ script >
</ HEAD >
< body >
< form id ="frmTestOpen" method ="post" runat = "server" >
返回值: < INPUT type ="text" id ="txtReturnValue" name = "txtReturnValue" >
< INPUT type ="button" value ="不关闭页面并返回输入的值" onclick = "CreateReturnValue(false);" >< br >
< INPUT type ="button" value ="关闭页面并返回输入的值" onclick = "CreateReturnValue(true);" >
</ form >
</ body >
</ HTML >
< HEAD >
< title > Test Open </ title >
< meta name ="GENERATOR" Content ="Microsoft Visual Studio .NET 7.1" >
< meta name ="CODE_LANGUAGE" Content ="C#" >
< meta name ="vs_defaultClientScript" content ="JavaScript" >
< meta name ="vs_targetSchema" content =http://schemas.microsoft.com/intellisense/ie5 >
< script >
function CreateReturnValue(closeWindow)
{
var txtReturnValue=document.getElementById("txtReturnValue");
if (txtReturnValue.value=="")
{
window.alert("请输入传递值");
return ;
}
var txtOpenerReturnValue=window.opener.document.getElementById("txtReturnValue");
txtOpenerReturnValue.value=txtReturnValue.value;
window.alert("值已经传给父窗体");
if (closeWindow)
{
window.opener=null;
window.close();
}
}
</ script >
</ HEAD >
< body >
< form id ="frmTestOpen" method ="post" runat = "server" >
返回值: < INPUT type ="text" id ="txtReturnValue" name = "txtReturnValue" >
< INPUT type ="button" value ="不关闭页面并返回输入的值" onclick = "CreateReturnValue(false);" >< br >
< INPUT type ="button" value ="关闭页面并返回输入的值" onclick = "CreateReturnValue(true);" >
</ form >
</ body >
</ HTML >
建议使用open()方法,因为showModdalDialog()方法在FireFox下不支持。
参考地址: http://www.webjx.com/htmldata/2005-08-02/1122939471.html