0

On my page I open up a popup using:

sideWindow = window.open(address,'pop',"height=200,width=200,scrollbars=1");
$(sideWindow).load(loadComplete);

And it triggers the function loadComplete after loading correctly.

After opening the window the user can change it address after and I redirect the popup using:

sideWindow.location.href=newAddress;

However it is not triggering loadComplete after it finishes loading as desired. What is the best way to perform the redirect so it will trigger loadComplete after the new page finishes loading?

Notes:
I do not have access to the source of the pages I am loading.
loadComplete should not run until after the images are loaded so $(sideWindow.document).ready would trigger to early.

user2623999
  • 81
  • 1
  • 3

1 Answers1

0

Figured I'd turn this into an answer. Here is how you'd open in a new window: As you can see it waits till a successful response to open the new window. I haven't used this because I'm not big on pop ups (I prefer to keep it in the DOM). That being said this should do the trick.

// AJAX window.open()
$('#btnAJAX').on("click", function(){
    $.ajax({
      url: "/user/login/",
      context: document.body,
      async:false,   //NOTE THIS very important turns call to blocking
      success: function(){  
         success = true
      }
    });
    if(success){ 
      window.open('http://google.com') //opens new page on success
    }
})

There is a lot of posts on the subject in stackoverflow like: window.open() works different on AJAX success

Community
  • 1
  • 1
Obj3ctiv3_C_88
  • 1,478
  • 1
  • 17
  • 29
  • Doesn't help with the getting loadComplete called after redirecting the popup window – user2623999 Jul 28 '15 at 17:17
  • Unfortunately there is no easy way because onload/ready isn't allowed for URIs outside of the domain. If necessary you could create an HTML page with a js file. In the js file is an immediate function that calls the required url. You wrap that result in the body. The function would use an AJAX call (that would obviously violate the same origin policy) to open the window. Or you could use IFRAME to open the window (which would be inside of the html page you create. Then you could call your page with onload. But this/what you're suggesting is considered bad practice. – Obj3ctiv3_C_88 Jul 28 '15 at 17:43
  • I am getting around the same origin policy using php for redirects which is why onload is working when the popup is first opened. – user2623999 Jul 28 '15 at 18:42