繁体   English   中英

使用HTML弹出窗口

[英]Pop up window using HTML

单击该按钮时,我要询问一系列消息,并为用户提供第二个确认选项。 但是,它不起作用。

<html>
<body>
    <p>Close the page to trigger the onunload event.</p>
    <script type="text/javascript">
        var changes = false;        
        window.onbeforeunload = function() {
            if (changes)
            {
                var message = "Are you sure you want to navigate away from this page?\n\nYou have started writing or editing a post.\n\nPress OK to continue or Cancel to stay on the current page.";
                if (confirm(message)) return true;
                else return false;
            }
        }
    </script>

    <button onClick='function;'> </input>
</body>
</html>

只需在function()中添加“ e”,变量就会更改。

之前:window.onbeforeunload = function(){

之后:window.onbeforeunload = function(e){

<html>
<body>
    <p>Close the page to trigger the onunload event.</p>
    <script type="text/javascript">   
        window.onbeforeunload = function(e) {            
            var message = "Are you sure you want to navigate away from this page?\n\nYou have started writing or editing a post.\n\nPress OK to continue or Cancel to stay on the current page.";
            if (confirm(message)) return true;
            else return false;
        }
    </script>

    <button onClick='window.close();'> </input>
</body>
</html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM