Javascript 開啟強制回應視窗

來源:互聯網
上載者:User
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                                    <a 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" />

參考文章:關於模態對話方塊關閉之後繼續執行伺服器端代碼的問題

在開啟的視窗中的伺服器控制項的事件中關閉開啟的頁面並且讓父視窗跳轉到另一個頁面的代碼1protected 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>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.