iframe自动适应高度!!

我说我行就是行 2011-10-12 12:54:19
从网上找了一推,到最后还是低头而归!不管怎么设置,都不行,求各位大神指点!


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function sizeChange()
{
window.status=AAA.document.body.scrollHeight;
document.all.AAA.height=AAA.document.body.scrollHeight;

}
</script>
</head>
<body>
<form id="form1" runat="server">
<!--如果是这样,直接套用自己根目录的地址就可以-->
<IFRAME id="AAA" src='GetCoreByClick.aspx' frameBorder=0 width="100%" scrolling=no onload="javascript:sizeChange();" > </IFRAME>
<!---可我现在想这样,直接运用网站地址,这样就不自动适应高度了-->
<%--<IFRAME id="AAA" src='http://www.sina.com.cn/' frameBorder=0 width="100%" scrolling=no onload="javascript:sizeChange()" > </IFRAME>--%>
</form>
</body>
</html>

如果各位愿意帮忙,请测试后发代码,网上的代码基本上我都找遍了,未找到合适的!谢谢

注释:src必须是网站地址,例如http://www.sina.com.cn
...全文
210 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 net_lover 的回复:]

没有啊,你嵌入别人的网站没用,要是都是你自己的,你可以设置嵌入的页面的大小与你的调用页面一致就可以了
[/Quote]
孟子E章,那我现在读取网页的内容,怎么也不行???


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Load();
}


}
private void Load()
{
HttpWebRequest RQ = (HttpWebRequest)WebRequest.Create("http://www.cnblogs.com");
StreamReader Sr = new System.IO.StreamReader(RQ.GetResponse().GetResponseStream(), Encoding.GetEncoding("gb2312"));
string str = Sr.ReadToEnd();
Sr.Close();
divcontent.InnerHtml= str;
}
我这样写,第一 :这个博客的样式全部乱了,图片加载不进来。。。。。。请问有什么方法可以把读取网页的内容的显示,跟原来的一模一样???

md5e 2011-10-13
  • 打赏
  • 举报
回复
AjaxGeturl.aspx

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using System.Net;
using System.IO;
using System.Text;
namespace Galsun.Air.Web
{
public partial class AjaxGeturl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string url = string.Empty;
url = Request.QueryString["url"];
Response.Write(GetResStr(url, "gb2312").Replace("location.href =","locationc ="));
Response.Write("\r\n<script>parent.right_scrollHeight = document.documentElement.scrollHeight;</script>\r\n");
Response.End();
}
}
string GetResStr(string url, string Encod)
{
WebRequest WReq;
WebResponse WResp;
StreamReader sr;
WReq = WebRequest.Create(url);
WResp = WReq.GetResponse();
sr = new StreamReader(WResp.GetResponseStream(), Encoding.GetEncoding(Encod));
string retValue = sr.ReadToEnd();
sr.Close();
return retValue;
}
}

}


<iframe frameborder="0" id="Right" name="Right" scrolling="yes" src="/AjaxGeturl.aspx?url=http://www.sina.com.cn" onload="gethieght()" style="width:100%;height:100%;" > </iframe>

<script>
var right_scrollHeight;
function gethieght()
{
alert(right_scrollHeight);
}
</script>


剩下的你懂的
jsyhello 2011-10-13
  • 打赏
  • 举报
回复
window.onload = function () {
document.getElementById("iframeContent").style.height = Math.max(parseInt(document.documentElement.clientHeight, 10) - 85, 500) + "px";
}
孟子E章 2011-10-13
  • 打赏
  • 举报
回复
你读取的只是源代码,里面的css,等都没有读进来,样式是没有的。
图片没有是因为路径的问题。

另外,你这么做是不行的,因为你读取的页面中也有<html><title><body>这些标记,会破坏你的页面的。
你只能读取到html源代码之后,去分析里面的代码,然后提取你想要的部分再显示,。
孟子E章 2011-10-12
  • 打赏
  • 举报
回复
不能跨域的。你必须是同一个网站的
  • 打赏
  • 举报
回复
哎,真的没有办法了啊,!哎,,伤心中。。。。
  • 打赏
  • 举报
回复
只要是在被嵌入的网页上去编程,就可以动态设置自己的iframe的高度。
  • 打赏
  • 举报
回复
浏览器从安全出发,只有嵌入的页面的脚本才能修改iframe的高度。我想没有一个大一点的制作浏览器软件的公司会做出可以从外部无原则可以随意修改iframe大小产品。
md5e 2011-10-12
  • 打赏
  • 举报
回复
这个可以试试,我一直在用

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>后台管理系统</title>
<style type="text/css">.navPoint {color: white; cursor: hand; font-family: Webdings; font-size: 9pt}</style>
<script language="JavaScript" type="text/javascript">
if (window.screen) {
var aw = screen.availWidth;
var ah = screen.availHeight;
window.moveTo(-3, -3);
window.resizeTo(aw+7, ah+7);
//
}

function switchSysBar()
{
if(switchPoint.innerText==3){
switchPoint.innerText=4
document.all("frmTitle").style.display="none"
}else{
switchPoint.innerText=3
document.all("frmTitle").style.display=""
}
}
</script>
</head>
<body style="margin: 0px;overflow:hidden; height:100%;">

<form id="form1" runat="server">
<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
<tr>
<td align="center" nowrap valign="top" id="frmTitle" height="100%">
<iframe id="Left" name="Left" src="MainMenu.aspx" scrolling="auto" frameborder="0" style="width:171px;height:100%" > </iframe>
</td>
<td style="width: 9pt" height="100%" id="cc">
<table border="0" cellpadding="0" cellspacing="0" height="100%" bgcolor="#66CC66">
<tr style="cursor:hand;">
<td id="qh" style="HEIGHT: 100%; width: 13px;" onclick="switchSysBar()" title="点击关闭/打开左栏">
<font style="FONT-SIZE: 9pt; CURSOR: default; COLOR: #ffffff">
<br/>
<br/>
<br/>
屏幕切换<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<span class="navPoint" id="switchPoint" title="点击关闭/打开左栏">3</span><br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
屏幕切换<br/>
<br/>
<br/>
<br/>
<br/>
</font></td>
</tr>
</table>
</td>
<td height="100%" width="100%" valign="top">
<iframe frameborder="0" id="Right" name="Right" scrolling="yes" src="Main.aspx" style="width:100%;height:100%;" > </iframe>
</td>
</tr>
</table>
</form>
<script>
function setAutoHeight(iframeElement, dheight) {

iframeElement.style.height =dheight ;

// 或者
//iframeElement.height = iframeWindow.document.body.offsetHeight ;
//iframeElement.width = iframeWindow.document.body.offsetWidth;

}
</script>

<script type="text/javascript">
if(window.screen.width<1024){switchSysBar()}

//调用函数setAutoHeight();
//document.getElementById("cc").style.height=document.body.scrollHeight;
setAutoHeight(document.getElementById("Left"), window.document.documentElement.clientHeight +"px");
setAutoHeight(document.getElementById("Right"), window.document.documentElement.clientHeight +"px");
document.getElementById("qh").style.height=window.document.documentElement.clientHeight +"px";
//alert(window.document.documentElement.clientHeight);
</script>


</body>
</html>

孟子E章 2011-10-12
  • 打赏
  • 举报
回复
没有啊,你嵌入别人的网站没用,要是都是你自己的,你可以设置嵌入的页面的大小与你的调用页面一致就可以了
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 net_lover 的回复:]
不能跨域的。你必须是同一个网站的
[/Quote]

没有办法了吗?

17,740

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧