不同窗口之间传递参数html版

83 篇文章 0 订阅
程序实现网页弹出页面输入值并返回父窗口:方便大家测试。
测试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 >
 
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 >

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 >

建议使用open()方法,因为showModdalDialog()方法在FireFox下不支持。

参考地址: http://www.webjx.com/htmldata/2005-08-02/1122939471.html
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值