views:

1709

answers:

6

I have a URL of a remote page from a different domain which I have to download, parse, and update DOM of the current page. I've found examples of doing this using new ActiveXObject("Msxml2.XMLHTTP"), but that's limited to IE, I guess, and using new java.net.URL, but I don't want to use Java. Are there any alternatives?

A: 

The XMLHTTPRequest object is common to most modern browsers and is what powers AJAX web applications.

JBRWilkinson
he said on a different domain...
Darko Z
If they create a standard it is possible that www.datejs.comhe could still use AJAX for this...though I would not recommend it...
Robert Massaioli
+1  A: 

Same domain policy is going to get you.

1) Proxy through your server. browser->your server->their server->your server->browser.

2) Use flash or silverlight. The 3rd party has to give you access. The bridge between javascript and flash isn't great for large amounts of data and there are bugs. Silverlight isn't ubiquitous like flash...

3) use a tag. This really isn't safe... Only works if 3rd party content is valid javascript.

Steve Brewer
+2  A: 

Whats about load an PHP Script via AJAX which does file_get_contents() ? This should work for different domain. If i understand correct.

codedevour
That's basically what Steve Brewer suggested. But I'd rather avoid using a proxy, if possible.
Vitaly
+1  A: 

Writing a server-side script that will retrieve the page's content for you is the way to go. You can use the XMLHttpRequest object to make an AJAX call to that script, which will just put through all html (?) for you.

Still, I advise against it. I don't know exactly how much you trust the other site, but the same origin policy exists for a reason. What is it exactly you are trying to do? Usually, there is a workaround.

JorenB
Same origin policy is the security way to do.Other site has an API ?
mere-teresa
Google Finance API doesn't provide a way to get stock quotes, however as mentioned here http://stackoverflow.com/questions/527703/google-financial-api-how-get-stock-quotes there is a way to get quotes like this: http://finance.google.com/finance/info?q=GOOG
Vitaly
So, you are trying to retrieve stock quotes from Google Finance? It helps to clarify exactly what it is you are trying to achieve :-)
JorenB
@JorenB Yes, I'm trying to get stock quotes and maybe some other supplementary info that's provided alongside using this unofficial API :)
Vitaly
A: 

I dont think you can do this according to the constraints of same origin policy. Two communicate between two domains using Iframes also we can use JS code but both domains need to have communicating code in them. The Child frame can contact the grandparent frame (window) but not here.

Since you are referring to some other url all togeather.

The only way is to do it using your server side code to access the content on the other domain.

moha297
A: 

Just use PHP:

<?php
$url = "http://www.domaintoretrieve.com";

ob_start();
include_once( $url );

$html = ob_get_contents();
ob_end_clean();

?>

$html contains the entire page to manipulate as needed.

Greg