Giving Parent Window Focus after Modal Closes
I execute a block of code when a particular window gets focus like this:
myWindow.addEventListener('focus', function(){
//Totally Rad Code...
}
I also fire a modal from this page, and when the user hits "Okay" to close that modal, it takes them back to the parent window (myWindow). But it doesn't give that window focus and thus doesn't execute my code above.
I can't just say myWindow.focus(); from within the modal, because it's out of context. I tried making the code block above a regular function inside a global include, but all the variables inside it are out of scope unless executed from inside myWindow.
Anyone have any ideas on what I can do to trigger focus for myWindow from within a modal as it closes?
1 Answer
-
Accepted Answer
It seems that the event focus never gets called if you use a Modal Window.
I tried but can't get any code to execute using this method.In the end, I used another event which achieve the same results.
I usedthe Modal Window çlosed eventSo, you have:
myWindow.addEventListener('focus', function(){
//Totally Rad Code…
}//// Above never gets called when Model Window close
ModalWindow.addEventListener('close', function(){
//Totally Rad Code…
}/// Gets called when Modal Window closes.
Test it!