Skip to content Skip to sidebar Skip to footer

Pass Data From Pop-up Window Back To Javascript

I have a window.open function in javascript that calls a page. I then want to grab the data from that page and return it to the javascript function. Can anyone help me do this? $('

Solution 1:

If the page in the popup is in the same domain as yours, you can use window.opener to access data of the opener windows

In your current window :

var winopened;
$("#popup").click(function(e) { 
    var url = $(this).attr('href');
    e.preventDefault();
    winopened = window.open(url, 'authWindow', "width=800,height=436");
});

if(winopened) {
  // call a function in the opened window : 
  res = winopened.functionInWindow();

}

hope it helped ...

Solution 2:

window.open will return your window object.

var myWindow = window.open

Now you can play with myWindow.

Solution 3:

The other posters answers are correct, in that they'll give you the window object. I'm not sure that's what you were asking for.

Here's a very simple way you can return the HTML from the page, if that's the "data" you need (otherwise disregard this answer).

This uses jQuery's AJAX $.get function to load HTML from a webpage, more at https://api.jquery.com/jQuery.get/

$.get(url, function( data ) {
   alert( "Data Loaded: " + data );
});

From here, you can do whatever you like with the "data" variable that is returned - store it, parse it, show it...

Post a Comment for "Pass Data From Pop-up Window Back To Javascript"