Click to See Complete Forum and Search --> : how to fetch innerHTML / Text of another page
zeedoo
06-19-2004, 07:13 AM
Hi,
When i open an external website using window.open, e.g. from www.domain.com i open www.google.com via window.open, then when trying to fetch its innerHTML from domain.com window, I get permission denied. How can i fetch its text/html from the parent window? Please help I really need this one ...
sciguyryan
06-19-2004, 07:23 AM
In theory you should be able to do it like so AS LONG as you assign the open to a variale first:
var NewWin = window.open("http://www.google.com");
NewWin. {Your Reference here};
Hope that helps :)
fredmv
06-19-2004, 07:35 AM
Originally posted by zeedoo
When i open an external website using window.open, e.g. from www.domain.com i open www.google.com This is precisely the problem. What you are doing here is violating the same origin policy (http://www.mozilla.org/projects/security/components/same-origin.html). In other words, you can only "talk" to other pages on your domain. If you must obtain data from another domain look into using an XMLHttpRequest object or perhaps better, a server-side solution.
zeedoo
06-19-2004, 07:41 AM
thanks for your quick replies, could you please give me more information / code on how do i fetch the content using Javascript and XMLHttpRequest ... Thanks ...
fredmv
06-19-2004, 07:44 AM
No problem. See: <http://www.codingforums.com/showthread.php?t=30449>.
zeedoo
06-19-2004, 07:44 AM
the thing i want to comment here is, i want the target page to be loaded in the window and then the text to be fetched for manipulation ... will XMLHttpRequest help in that?
fredmv
06-19-2004, 07:49 AM
In fact, if you want to get this working entirely cross-browser you'll have to use server-side. Mozilla won't let you access other domains in this context (of which I would suspect). However, IE on the other hand does (living up to its insecure reputation). In any case, this method returns to current source code of the page/file you request. You will not be able to execute JavaScript on that page; you'll just have access to the markup.
zeedoo
06-19-2004, 08:09 AM
well can i with this method, display the target site in its windows and also search its code from the parent window ? If so please please give some lines of code which will achieve this ...