C# 自动调整iframe的大小不起作用
我的html代码是C# 自动调整iframe的大小不起作用,c#,asp.net,C#,Asp.net,我的html代码是 <script language="JavaScript" type="text/javascript"> function autoResize(id) { var newheight; var newwidth; if (document.getElementById) { newheight = document.getElementById(id).contentWindow.document.bod
<script language="JavaScript" type="text/javascript">
function autoResize(id)
{
var newheight;
var newwidth;
if (document.getElementById)
{
newheight = document.getElementById(id).contentWindow.document.body.scrollHeight;
newwidth = document.getElementById(id).contentWindow.document.body.scrollWidth;
}
document.getElementById(id).height = (newheight) + "px";
document.getElementById(id).width = (newwidth) + "px";
}
</script>
<asp:DataList ID="dtlhtml" runat="server" Width="100%">
<ItemTemplate>
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<iframe src='<%#Eval("html") %>' width="713" height="250" id="iframe1" frameborder="0" onload="autoResize(this.id);"></iframe>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
这不适用于本地,但适用于在线
问题
我在firefox上在线运行,24.0版运行正常,但在我的两个朋友的电脑上,相同版本的滚动即将到来。如果您的情况不正确,请执行以下操作
if(document.getElementById(id))
{
}
虽然我不确定,但我想问题在于:数值+字符串可能会导致错误
document.getElementById(id).height = (newheight) + "px";
document.getElementById(id).width = (newwidth) + "px";
你可以把它写成
document.getElementById(id).height = newheight;
document.getElementById(id).width = newwidth;
此外,您还可以删除“px”,因为默认情况下,长度仅以像素为单位 嘿,我的问题解决了,因为我给了path
dr["html"] = "http://stackoverflow.com/file/1.html";
但正确的方法是给我的iframe指定调用html页面的路径
dr["html"] ="http://www.stackoverflow.com/file/1.html"
dr["html"] ="http://www.stackoverflow.com/file/1.html"