WIndow A use window.open to get another window B.
Could the javascript in A access the content of B?
two windows A,B accessing the content of the child window
Moderator: General Moderators
- 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
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
I think you should be able to access it element by element from the document object. Use something like:wvoyance wrote:WIndow A use window.open to get another window B.
Could the javascript in A access the content of B?
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
Then...I can do cross domain operation? My final goal is to get the content of other website and extract data I want.x_mutatis_mutandis_x wrote:I think you should be able to access it element by element from the document object. Use something like:wvoyance wrote:WIndow A use window.open to get another window B.
Could the javascript in A access the content of B?Code: Select all
windowB = window.open('<url to B>'); documentB = windowB.document; //documentB.getElementById('id1').innerHTML //documentB.getElementById('id2').innerHTML etc..
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
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:
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.
Code: Select all
echo file_get_contents($_REQUEST['url']);Then with jQuery or the like, you should be able to parse the entire document with normal DOM methods.