如何用js调用其他网站上的html内容做数据,不是iframe。。

来源:百度知道 编辑:UC知道 时间:2024/05/27 00:03:47
现在要调用其他网站已经生成的静态html网页,谁能告诉我客户端要用什么方法?我知道jquery的getJSON,不过那个要服务器回调,有人知道怎么解决这个问题?
o(∩_∩)o...哈哈,问题自己解决了,还是用getJSON的方法。。。
晚上就把问题关了,想讨论的朋友可以回帖。。

直接用JS做不到,脚本是不允许跨域操作的
可以通过服务器端为中介来获取:
a.aspx
<html>
<body>
<iframe id="frm" name="frm" src="about:blank" style="visibility:hidden" />
<div id="con"></div>
<script>
var url = "http://www.baidu.com";
var frm = document.getElementById("frm");
frm.src="a.aspx?url="+escape(url);
frm.onload = function(){
document.getElementById("con").innerHTML=window.frm.document.innerHTML;
};
</script>
</body>
</html>
a.aspx.cs
page_load
{
if(Request["url"]!=null){
string html = new System.Net.WebClient().DownloadString(Request["url"]);
Response.Write(html);
Response.End();
}
}

不可能,js不支持跨域操作!就算你本地把浏览器的安全降到最低可以实现,但是你总不能要所有的浏览者都这么做吧!

可以调