0

可能重复:
规避同源策略的方法

无论如何要从外部站点获取内容,例如我想通过使用 Javascript 或 JQuery 从客户端站点中的url http://www.readwriteweb.com/获取内容

4

3 回答 3

2

除非站点设置为允许跨域请求,否则出于安全原因,您无法访问其他站点的 DOM。

这称为同源策略。如果您控制服务器,则有多种解决方法。

另一种选择是自己在服务器端提取数据并将其从您的域传递给客户端。

于 2012-08-03T03:20:28.327 回答
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; });

于 2012-11-18T18:17:34.927 回答
0

如果您的外部站点与您的站点不在同一个域中,那么不。我建议您使用 JSONP 对象在不同域的站点之间发送/接收。

于 2012-08-03T03:19:54.410 回答