Page 1 of 1

two windows A,B accessing the content of the child window

Posted: Mon Apr 30, 2012 9:11 am
by wvoyance
WIndow A use window.open to get another window B.
Could the javascript in A access the content of B?

Re: two windows A,B accessing the content of the child windo

Posted: Mon Apr 30, 2012 12:29 pm
by Christopher
Look at the window.opener property.

Re: two windows A,B accessing the content of the child windo

Posted: Mon Apr 30, 2012 12:40 pm
by x_mutatis_mutandis_x
wvoyance wrote:WIndow A use window.open to get another window B.
Could the javascript in A access the content of B?
I think you should be able to access it element by element from the document object. Use something like:

Code: Select all

windowB = window.open('<url to B>');
documentB = windowB.document;

//documentB.getElementById('id1').innerHTML
//documentB.getElementById('id2').innerHTML etc..


Re: two windows A,B accessing the content of the child windo

Posted: Mon Apr 30, 2012 10:11 pm
by wvoyance
x_mutatis_mutandis_x wrote:
wvoyance wrote:WIndow A use window.open to get another window B.
Could the javascript in A access the content of B?
I think you should be able to access it element by element from the document object. Use something like:

Code: Select all

windowB = window.open('<url to B>');
documentB = windowB.document;

//documentB.getElementById('id1').innerHTML
//documentB.getElementById('id2').innerHTML etc..

Then...I can do cross domain operation? My final goal is to get the content of other website and extract data I want.
Now that I can use window.open to get any other site from local javascript, and access to the content of that window.
Then, it is already cross domain, isn't it?

Re: two windows A,B accessing the content of the child windo

Posted: Tue May 01, 2012 1:34 pm
by tr0gd0rr
Without using CORS, there is no way to get content of another web site. Not through AJAX, iframe, or window.open. One thing you can do is write a php script that will return you the html of the foreign page. At it's simplest, you could do:

Code: Select all

echo file_get_contents($_REQUEST['url']);
You would probably want to do some security checks like make sure the user is logged in.
Then with jQuery or the like, you should be able to parse the entire document with normal DOM methods.