0

Possible Duplicate:
Ways to circumvent the same-origin policy

Is there anyway to get content from external site for example i want to get content from url http://www.readwriteweb.com/ in client site by using Javascript or JQuery

3
  • this site I think offers rss feed why not use that
    – COLD TOLD
    Aug 3, 2012 at 3:18
  • I don't see any CORS headers so no
    – Musa
    Aug 3, 2012 at 3:20
  • not all of sites have rss feed, i want to get bare html content
    – MQuy
    Aug 3, 2012 at 3:20

3 Answers 3

2

Unless the site is set up to allow cross-origin requests, you can't access the DOM of another site for security reasons.

This is known as the Same origin policy. There are a number of ways around it if you control the server.

The other option is to pull the data yourself server-side and deliver this to the client from your domain.

1

Here are two options:

  1. Use an iframe to embed a web page of the external site in your page. You can only embed an entire page, including all its advertising and navigation sites, but on some external sites you can find versions of the page intended for mobile or for printing that might look reasonable when embedded.
  2. Use a public CORS proxy. The only one I have found is http://www.corsproxy.com/ . Personally I am suspicious of that site as there is no TOC, privacy policy, or even any indication of who runs the site. However if yours is some small project, where you don't care about privacy, security, reliability, or scaling you might try it. Here is an example of usage adapted from the site:

    $.get( 'http://www.corsproxy.com/en.wikipedia.org/wiki/Http', function(response) { document.body.innerHTML = response; });

0

If your external site is not in the same domain as your site then No. I would suggest you to use JSONP objects to send/receive between sites in different domain.

4
  • i know there is around way to do that by using ajax to send request to my server and my server fetch content after that sending content back. But i want to do it only from client side, possible?
    – MQuy
    Aug 3, 2012 at 3:24
  • Well, you can still use AJAX but your server should send JSON objects to the client and the client should be able to parse the result. Aug 3, 2012 at 3:27
  • maybe, you don't understand what i mean. I want to fetch content only client side not fetch in server side
    – MQuy
    Aug 3, 2012 at 3:28
  • If you don't have control over the server then NO. Aug 3, 2012 at 3:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.