views:

66

answers:

3

How to use in jQuery data from window.open

  w = window.open("http://google.com",
            'test_window',
            'left=20,top=20,width=500,height=500,toolbar=1,resizable=1');
  browser = w.document;  
  // execute commands in browser
  $(browser).ready(function(){
    alert($('input', browser).attr('name'));
  });
  // close browser
  w.close();

In this example I want to open new pop-up window, load Google page and get information about loaded page element (name of input filed).

I try to do this, but not found solution. Please, help me.

A: 

I believe you would need to open it in an iFrame.

or create a new window (http://your-domain.com/google.html) with an iframe embeded, then you can use jQuery to query the dom of the external content.

Jud Stephenson
I don't think that will work, since you would still be executing a script which access an external DOM.
Joel Potter
If he created his own page, (e.g. //his-domain.com/google.html) and on that page, loaded google in an iframe, he could manipulate the dom from google.html.
Jud Stephenson
A: 

This is called cross site scripting (XSS). Your page (i.e. somedomain.com) is executing a script which is trying to read data off another window which has loaded a different domain (google.com). Modern browsers will prevent this since it is a security concern.

Imagine if you had a compromised site open in one window, and your bank site open in another. With XSS an attacker could sniff your bank info from the compromised site.

The only way to do such a thing is to disable XSS filters on the client (not a good idea), or install an application which does the job you are attempting to do with javascript. However, depending on what you are trying to accomplish, Google API's may offer the access you need without all that work.

Joel Potter
A: 

Please tell us what are you trying to do. maybe there is a better solution. If you want to use google search stuff in your site there is a apis for that. Google search API

XGreen