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

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
wvoyance
Forum Contributor
Posts: 135
Joined: Tue Apr 17, 2012 8:24 pm

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

Post by wvoyance »

WIndow A use window.open to get another window B.
Could the javascript in A access the content of B?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post by Christopher »

Look at the window.opener property.
(#10850)
x_mutatis_mutandis_x
Forum Contributor
Posts: 160
Joined: Tue Apr 17, 2012 12:57 pm

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

Post 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..

User avatar
wvoyance
Forum Contributor
Posts: 135
Joined: Tue Apr 17, 2012 8:24 pm

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

Post 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?
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

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

Post 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.
Post Reply