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

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

问题描述

我有一个来自不同域的远程页面的 URL,我必须下载、解析和更新当前页面的 DOM.我找到了使用 new ActiveXObject("Msxml2.XMLHTTP") 执行此操作的示例,但我猜这仅限于 IE,并且使用 new java.net.URL,但我不想使用 Java.有其他选择吗?

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) 通过您的服务器代理.浏览器->您的服务器->他们的服务器->您的服务器->浏览器.

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

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

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) 使用标签.这真的不安全......只有在 3rd 方内容是有效的 javascript 时才有效.

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

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

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