Window override. Close in Javascript

I am trying to override the window.close() method in javascript . Here is my code.

  (function () { var _close = window.close; window.close = function () { window.opener.alert("test"); _close(); }; })(); 

I am trying to associate this code with a new window and execute internal code when closing a new window. Is it possible to override window.close as follows?

+3
javascript jquery javascript-events
Aug 22 '13 at 12:52
source share
1 answer

try it

You can use the window.onbeforeunload event to call any function. However, warning, confirmation, confirmation flags are not allowed. You can return any line to show any message.

 //var _close = window.onbeforeunload; window.onbeforeunload = function () { // window.opener.alert("test"); //_close(); return callBack(); }; function callBack() { return "Testing"; } 

If you want to close any other child window

You can try this

 var k = window.open("url"); k.onbeforeunload = callBack; 
+2
Aug 23 '13 at 6:12
source share



All Articles