如何使用JavaScript获取远程页面的内容? [英] How to get the content of a remote page with JavaScript?

查看:133
本文介绍了如何使用JavaScript获取远程页面的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个来自不同域的远程页面的URL,我必须下载,解析和更新当前页面的DOM。我已经找到了使用新ActiveXObject(Msxml2.XMLHTTP)的示例,但这仅限于IE,我猜,并且使用新的java.net.URL ,但我不想使用Java。有没有其他的办法?

解决方案

相同的域名政策会帮助您。

1)通过您的服务器进行代理。浏览器 - >你的服务器 - >他们的服务器 - >你的服务器 - >浏览器。

2)使用flash或silverlight。第三方必须为您提供访问权限。 javascript和flash之间的桥梁对于大量数据并不好,并且存在错误。 Silverlight并不像flash那样无处不在......



3)使用标签。这真的不安全......只有第三方内容是有效的javascript才可用。


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?

解决方案

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.

这篇关于如何使用JavaScript获取远程页面的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆