简体   繁体   English

弹出警报关闭

[英]Alert on Pop Up Close

I have developed a Window Pop up, using below code: 我使用以下代码开发了一个弹出窗口:

UPDATED CODE: 更新的代码:

Parent.html Parent.html

<a class="btn btn-primary" onclick="PopUp();">Pop Up</a>

<script>
 var popup;
 function PopUp() {
    document.getElementById('myModal').style.display="block";

    popup = window.open('popup.html', 'Google', width=700, height=600);

     popup.onbeforeunload = function(){  
     alert("close");        
     document.getElementById('myModal').style.display="none";
   }
}
</script>

POPUP.html POPUP.html

window.location = "http://www.google.com";

My requirement is that whenever someone close the Window Pop up there should be alert on Parent.html. 我的要求是,每当有人关闭窗口弹出窗口时,Parent.html上都应该发出警报。 As we don't have any control on Pop up window. 由于我们对“弹出窗口”没有任何控制。

Is, there any way to do this.?? 是的,有什么方法可以做到这一点。

Try with something like thhis.... 试试这样的东西。

$.confirm({
    title: 'Confirm!',
    content: 'Simple confirm!',
    buttons: {
        confirm: function () {
            $.alert('Confirmed!');
        },
        cancel: function () {
            $.alert('Canceled!');
        },
        somethingElse: {
            text: 'Something else',
            btnClass: 'btn-blue',
            keys: ['enter', 'shift'],
            action: function(){
                $.alert('Something else?');
            }
        }
    }
});

You can store the result of window.open : 您可以存储window.open的结果:

let popup = window.open()
popup.onbeforeunload = function(){ }

https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload https://developer.mozilla.org/zh-CN/docs/Web/API/WindowEventHandlers/onbeforeunload

EDIT 编辑

It only works if the popup opens the site in the same domain. 仅当弹出窗口在同一域中打开该站点时,它才起作用。

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

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