且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用JavaScript获取远程页面的内容?

更新时间:2023-02-24 13:54:58

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

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.