0

I am trying to close a window which have been opened in the following way:

var myWindow;
function openLink(){
    myWindow = window.open("http://mydir.com", "MsgWindow", "width=600, height=400, left=250, top=200");

    }

This opens a window inside a some kind of popup (Here you can see how it works)

What i want to do is when my ajax call finishes (in the opened window) close the window. I am trying with this:

 $.ajax ({
  url: "php/copia.php",
  type: "post",
  data: {"params": result,
  "dirDest":dirDest},
  success: function(response) {
        $.mobile.loading('hide');
        window.parent.postMessage('Close popup', '*');//I am trying to send a message to the parent window but it doesnt work
    }

}); 

In the window which opens the new window i have the following:

$( document ).ready(window.addEventListener("message", closePopup, false));

function closePopup(event) {
        myWindow.close();
    }
A1t0r
  • 469
  • 5
  • 26
  • 1
    I think you need window.opener in stead of window.parent See http://stackoverflow.com/questions/11313045/when-to-use-window-opener-window-parent-window-top – Remco van Dalen May 30 '14 at 09:41

1 Answers1

0

Solution #1: just call window.close() in success callback.

Solution #2: replace window.parent with window.opener http://www.w3schools.com/jsref/prop_win_opener.asp http://www.w3schools.com/jsref/prop_win_parent.asp

Read more here: When to use window.opener / window.parent / window.top

Community
  • 1
  • 1
Anpher
  • 4,567
  • 24
  • 24