0

I have a popup on which i have a button, on click of it, a popup opens. When i close the first popup, the second popup should also close. The second popup should not close during first popup page reload.

function openWindow() {
    var url = "http://www.google.com";
    popupWindow = window.open(url,window.self");
    window.onbeforeunload = function() { popupWindow.close(); };
}

I did try this, but as per the above code, the second popup closes for every page reload.

Sam
  • 77
  • 7
  • The `beforeunload` event fires whenever the page is about to be unloaded; that includes both when the window is closed and when it is reloaded, as you discovered. There is no way to detect one or the other specifically. – Herohtar Jun 18 '19 at 04:58
  • 3
    Possible duplicate of [javascript beforeunload detect refresh versus close](https://stackoverflow.com/questions/11453741/javascript-beforeunload-detect-refresh-versus-close) – Herohtar Jun 18 '19 at 04:58

0 Answers0