【问题标题】:How to check whether (X) button in clicked in popup window如何检查是否在弹出窗口中单击了(X)按钮
【发布时间】:2017-11-23 13:48:31
【问题描述】:

我正在尝试从子窗口将值设置为父窗口中的隐藏字段,并且只想在弹出窗口关闭时将值设置为父窗口。

当我使用按钮关闭窗口时,这工作正常。

按钮的脚本是: onclick="javascript:window.close();"

但是当我单击标题栏中的 (X) 按钮时,同样的情况会失败。谁能帮我解决这个问题

【问题讨论】:

  • 你有任何与 onunload 事件处理程序相关的 return false 吗?
  • 不,我对该方法没有任何回报

标签: javascript html


【解决方案1】:

使用 onBeforeUnload。

【讨论】:

  • 我在这个jsp中使用struts标签来显示错误信息。

  • 会发生什么是页面再次重新加载,这个方法我调用了两次。
  • onunload 也一样
【解决方案2】:
<html>
<script type="text/javascript">
    function ConfirmClose()
    {
       if ((event.clientY < 0) ||(event.altKey) ||(event.ctrlKey)||((event.clientY < 129) && (event.clientY>107)))
        {
//event.altKey When press Alt +F4
//event.ctrlKey When press Ctrl +F4
//event.clientY 107 or 129 is  Alt F4 postion on window screen it may change base on screen resolution
alert('window closing');
        }
    }
</script>

<body topmargin='0'  onbeforeunload="ConfirmClose()">
</body>
 </html>

【讨论】:

    【解决方案3】:

    最好的方法是使用 window.onunload,但是当你按下 ctrl+r(即刷新)时也会触发这个事件,所以请检查一下。

    【讨论】:

    • 有没有办法阻止窗口刷新以防止它成为潜在问题?
    【解决方案4】:

    我发现jQuery dialog 非常容易创建弹出窗口。这可以防止浏览器阻止“真实”弹出窗口以及您在此处描述的问题。

    【讨论】:

      【解决方案5】:

      给你的文件:http://www.openjs.com/scripts/events/keyboard_shortcuts/

      shortcut.add("Ctrl+Shift+X",function() {
          alert("Hi there!");
      });
      

      下载:http://www.openjs.com/scripts/events/keyboard_shortcuts/shortcut.js

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多