1. 程式人生 > >點選iframe 中某頁面的一個按鈕實現跳轉到iframe外面的窗體裡面

點選iframe 中某頁面的一個按鈕實現跳轉到iframe外面的窗體裡面

Default.aspx

protected void Page_Load(object sender, EventArgs e)
        {
            Response.Redirect("WebForm1.aspx");
        }
WebForm1.aspx
<body>
    <form id="form1" runat="server">
    <div>
    <iframe src="About.aspx"></iframe>
    </div>
    </form>
</body>

About.aspx
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script language="javascript" type="text/javascript">

        function Button2_onclick() {
            window.open('WebForm2.aspx', 'newwindow', 'height=600,width=600,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
            top.opener = null;
            top.close();     //注意,   不可跨域 

        }

    </script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        關於
        <input id="Button2" type="button" value="button" onclick="return Button2_onclick()" /></h2>
    <p>
        將內容放置在此處。
    </p>
</asp:Content>

這樣就可以預覽Default.aspx時展示Webform1.aspx,這時點選位於iframe中About.aspx的Button2即可跳轉到WebForm2.aspx(已經沒有iframe了)

ClientScript.RegisterStartupScript(this.GetType(), "ggg", "<script>parent.document.location.href = \"Login.aspx\";</script>");