简体   繁体   English

如何在javascript中关闭子窗口显示确认消息?

[英]How to show confirm message on close of child window in javascript?

I have a parent window and when I click a link from parent window, the link opens in a new window. 我有一个父窗口,当我从父窗口单击链接时,链接将在新窗口中打开。 I need to show confirm message on close of child window.(ie the opened link ) 我需要在子窗口关闭时显示确认消息。(即打开的链接)

childWindow = window.open("http://www.google.com","width=400, height=400");

I like confirm close for child window. 我喜欢确认关闭儿童窗口。 like 喜欢

childWindow.close(function(){var confirmClose=confirm("Are you sure to close ?");
});

If the user clicks "OK" of the confirm box then the child window will be closed, else if the user click "Cancel" then the child window will not be closed 如果用户单击确认框的“确定”,则子窗口将关闭,否则如果用户单击“取消”,则子窗口将不会关闭

To set up a confirm dialogue, add a listener to the beforeunload event of the (child)window as demonstrated in Confirm message on browser page close and prevent the action eventually. 要设置确认对话框,请在(子)窗口的beforeunload事件中添加一个监听器,如关闭浏览器页面上的确认消息中所示,并最终阻止该操作。

If you call childWindow.close() , the window will get closed instead of hooking a callback function. 如果调用childWindow.close() ,窗口将关闭,而不是挂钩回调函数。

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

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