0

I have a button, if user clicks on that button I am opening a external window as follows:

function btnClick(){

window.open("http://localhost/index.html");

/* I'LL WRITE SOME OTHER CODE AFTER THIS */

}

I want the javascript function to wait for that window to get closed before executing the rest of my code. Is there any way of doing that ?

user3191903
  • 237
  • 2
  • 6
  • 14
  • 1
    http://stackoverflow.com/questions/3291712/is-it-possible-to-open-a-popup-with-javascript-and-then-detect-when-the-user-clo – cha55son Mar 11 '14 at 20:04

3 Answers3

1
window.onbeforeunload = closingCode;
    function closingCode(){
       // do something...
       return null;
    }

A similar question which should help Here

Community
  • 1
  • 1
JayD
  • 6,173
  • 4
  • 20
  • 24
0

Maybe you can use the 'While' loop?

PS: I am a newbie, it is just a 'Maybe'.

EDIT:

      While (/*code for closing a window*/) {
      /*Function that you want to be executed after the 
      Window has been closed*/               
       };

You maybe also can do:

        If (/*window is closed code*/) {
       /*Code of Function etc*/
        };
TimonSeldenrijk
  • 499
  • 1
  • 4
  • 13
0

There are two events named window.onbeforeunload and window.onunload that you can use to accomplish this: JavaScript question: Onbeforeunload or Onunload?.

Community
  • 1
  • 1
ElGavilan
  • 6,610
  • 16
  • 27
  • 36