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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM