打開一個頁面,並監聽該頁面的關閉事件


頁面1

<!--WebForm1.aspx-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript">
        var subWindows
        function OpenWin() {
            subWindows = window.open("WebForm2.aspx", "NewWindows");
            subWindows.attachEvent("onunload", OnWindowsClose);
        }
        function OnWindowsClose() {
            alert(subWindows.document.getElementById("HiddenField1").value)
        }  
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="打開" OnClientClick="OpenWin(); return false;" />
    </div>
    </form>
</body>
</html>


頁面2

<!--WebForm2.aspx-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript">
        function CloseWin() {
            document.getElementById("HiddenField1").value = "asdfasf";
            window.close();
        }  
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="關閉" OnClientClick="CloseWin();return false;" />
        <asp:HiddenField ID="HiddenField1" runat="server" />
    </div>
    </form>
</body>
</html>

 


免責聲明!

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



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