Javascript 打开模式窗口

1      < script language = " javascript " >
2         function  openModalDialog(url, width, height)
3          {
4            window.showModalDialog(url, """dialogWidth="+width+"px;dialogHeight="+height+"px");
5            window.location.reload(true); 
6        }

7      < / script>

打开以后关闭窗户,父页面会自动刷新

调用例子:
在GridView的模板列里面使用:
1 < asp:TemplateField >
2                                  < ItemTemplate >
3                                      < href ="javascript:openModalDialog('Edit.aspx?Id=<%# Eval(" Id") % > ',840,500);">Detail </ a >  
4                                  </ ItemTemplate >
5                              </ asp:TemplateField >
在普通页面的调用例子:
<a href="javascript:openModalDialog('Edit.aspx?Id=1',840,500);">Detail</a>

在打开的页面中的<head></head>之中需要加上如下的代码
<base target="_self" /> <!--Prevent opening new window-->
 <!--Disable the cache-->
    <meta http-equiv="pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
    <meta http-equiv="expires" content="Mon, 23 Jan 1978 20:52:30 GMT" />


参考文章:关于模态对话框关闭之后继续执行服务器端代码的问题

在打开的窗口中的服务器控件的事件中关闭打开的页面并且让父窗口跳转到另一个页面的代码
1 protected   void  Button1_Click( object  sender, EventArgs e)
2          {
3            string script = @"<script language='javascript'>window.close();window.dialogArguments.location.href='Default.aspx';</script>";
4
5            ClientScript.RegisterStartupScript(this.GetType(), "close", script);
6        }

在使用showModalDialog时需要将window当成参数传递给子视窗, 如此视窗才能使用window.dialogArguments.location

1 < script language = " javascript " >
2          function  ss()
3          {
4            window.showModalDialog("SubPage.aspx", window, "dialogWidth=440px;dialogHeight=300px");
5        }

6      < / script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值