iframe runat="server" 怎么自動適應大小?
<iframe id="frameNavigation" frameborder="0" runat ="server" ></iframe>我在Page_Load()
{
frameNavigation.Attributes.Add("onload", "autoResizeIframe()");
}又定義了
<script type ="text/javascript" >function autoResizeIframe()
{
document.all.frameNavigation.height="300";
//parent.frames("frameNavigation").style.height="300";
//parent.frames("frameNavigation").style.height=parent.frames("frameNavigation").document.body.scrollHeight;//window.frameNavigation.document.body.scrollHeight;
//height="300";
}</script>但運行後沒生效
<iframe id="frameNavigation" frameborder="0" runat ="server" ></iframe>我在Page_Load()
{
frameNavigation.Attributes.Add("onload", "autoResizeIframe()");
}又定義了
<script type ="text/javascript" >function autoResizeIframe()
{
document.all.frameNavigation.height="300";
//parent.frames("frameNavigation").style.height="300";
//parent.frames("frameNavigation").style.height=parent.frames("frameNavigation").document.body.scrollHeight;//window.frameNavigation.document.body.scrollHeight;
//height="300";
}</script>但運行後沒生效
解决方案 »
- 高手来一下,禁用了Viewstate后,Checkbox仍不断生成viewstate
- 转换时间
- Asp.net中使用Session 的会话时间问题
- 网络通讯问题
- 请教一个关于水晶报表部的问题?
- 一个奇怪的现象!table嵌套td和iframe,td中文字一多,iframe就不行拉!
- 求算法:随机、乱序、不重复取得数据库里面的记录。
- 超难度问题 aspnet_wp.exe could not be started. The error code for the failure is 80070718
- asp.net网站后台怎样设置数据库备份
- 对于有回发操作的页面,我用window.history.back()要调用两次以上才行,怎么解决?
- 输入问题?
- 密码如何加密?
window.resizeTo(document.body.scrollWidth,document.body.scrollHeight);
}这个是根据 iframe 调用页面的高度自动调整页面高度的,看看。
function f_frameStyleResize(targObj){
var targWin=targObj.parent.document.all[targObj.name];
if(targWin!=null){
var HeightValue=targObj.document.body.scrollHeight;
targWin.style.pixelHeight=HeightValue+15;
}}
function f_iframeResize(){
f_frameStyleResize(self);
}
window.onload=f_iframeResize;
</script>
另 f_frameStyleResize(self);裡的參數是self? 還是 iframe的id呀
{
document.all.frameNavigation.height="300";
//parent.frames("frameNavigation").style.height="300";
//parent.frames("frameNavigation").style.height=parent.frames("frameNavigation").document.body.scrollHeight;//window.frameNavigation.document.body.scrollHeight;
//height="300";
}</script>
直接賦值都沒效哦,頂,求解決方法
function autoResizeIframe()
{
document.all.frameNavigation.height="200";
}
</script>直接写到页面底部就可以了
<script type="text/javascript"> document.all.frameNavigation.height="200";
</script>
<iframe id="frameNavigation" frameborder="0" runat ="server" height="300"></iframe>
就行了我主要是想它能自動適應大小,
而且現在發現放在javascript function autoResizeIframe()裡,就是賦它固定值好像也沒效,好像這個函數沒有執行一樣
{ frameNavigation.Attributes["src"] = "frmMakeScheduleDetail.aspx?iordno=" + ((GridView)sender).SelectedRow.Cells[2].Text;
}
{
document.all.frameNavigation.style.height="300";
}
還是不行
如果直接<iframe id="frameNavigation" frameborder="0" runat ="server" onload="autoResizeIframe()"></iframe>
在編譯是出錯,說是找不到autoResizeIframe()這個東東,估計編譯是在找後臺的這個過程但
frameNavigation.Attributes.Add("onload", "autoResizeIframe()");
又看不到效果,不知道到底有沒有執行autoResizeIframe()
但查看源代碼裡面就有
<iframe id="ctl00_ContentPlaceHolder1_frameNavigation" frameborder="0" onload="autoResizeIframe()" src="frmMakeScheduleDetail.aspx?iordno=0610003"></iframe>鬱悶
<html>
<body onload="autoResizeIframe();">
<iframe src="http://community.csdn.net/Expert/ForumList.asp?typenum=1&roomid=5202"
height=100 id=frameNavigation></iframe>
<script language=javascript>
function autoResizeIframe()
{
document.all.frameNavigation.style.height="300";
}
</script>
</body>
</html>
<body>
<iframe src="http://community.csdn.net/Expert/ForumList.asp?typenum=1&roomid=5202"
height=100 id=frameNavigation onload="autoResizeIframe();"></iframe>
<script language=javascript>
function autoResizeIframe()
{
document.all.frameNavigation.style.height="300";
}
</script>
</body>
</html>也是行的呀?!
height=100 id=frameNavigation runat="server"></iframe>
上面写错了,把下面这个放到页面底部就可以了
<script type="text/javascript"> document.all.frameNavigation.height="200";
</script>
==================
你把200换成<% = 后台变量 %>不就动态了?
parent.document.all[window.name].style.height=document.body.scrollHeight;
来强行改变容器对自己设置的高度。
<iframe id="frameNavigation" frameborder="0" runat ="server" ></iframe>
如果不加,在後臺代碼裡取不到frameNavigation這個控件 就是因為現在直接賦值都搞不定,所以先要搞定直接賦值,再搞 自適應請 sp1234(满城尽是意淫女——如果百度收购腾讯,市场战胜技术) 再幫手試下
<body>
<hr />
<iframe src="a.htm" height="100" id="frameNavigation" name="frameNavigation"
scrolling="no" frameborder="0"></iframe>
<hr />
</body>
</html>
文件a.htm:
<html>
<body onload="parent.document.all[window.name].style.height=document.body.scrollHeight;">
askdfaklsdfas<br />
dfa<br />
sdf<br />
as<br />
dfa<br />
sdf<br />
as<br />
dfa<br />
sdf<br />
sssssssssssssssssssss
</body>
</html>
<script runat="server">
protected void Button1_Click( object sender, System.EventArgs e )
{
frameleft.Attributes["Src"] = "http://dotnet.aspx.cc"; }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
你可以看下这个帖!
孟子老大解决的哦!
http://community.csdn.net/Expert/topic/5245/5245033.xml?temp=.4968683
如果加了runat="server" 就沒辦法了?
<body>
<hr />
<iframe src="a.htm" height="100" id="frameNavigation" name="frameNavigation"
scrolling="no" frameborder="0"></iframe>
<hr />
</body>
</html>
文件a.htm:
<html>
<body onload="parent.document.all[window.name].style.height=document.body.scrollHeight;">
askdfaklsdfas<br />
dfa<br />
sdf<br />
as<br />
dfa<br />
sdf<br />
as<br />
dfa<br />
sdf<br />
sssssssssssssssssssss
</body>
</html>
===================================
上面這段代碼我試了沒問題,但將onload="parent.document.all[window.name].style.height=document.body.scrollHeight;"放到我的SRC frmMakeScheduleDetail.aspx 中,出問題了:parent.document.all[...].style是NULL或不是一個物體我的父ASPX套用了一個主版頁面,不知跟這有沒有關係
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="frmMakeSchedule.aspx.cs" Inherits="RemoteForms_frmMakeSchedule" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type ="text/javascript" src= "../CSS/calendar.js"></script>
<div style ="vertical-align:middle " >
<center>
<table border="0" width="2000" cellspacing="0" cellpadding="0" height="300">
<tr>
<td style="width:94%; vertical-align: middle; text-align: left; height: 19px;">
訂單號:<asp:TextBox ID="TxtIOrdNo" runat="server" Width="105px"></asp:TextBox>
客戶:<asp:DropDownList ID="DdlCusNo" runat="server">
</asp:DropDownList>
工廠交期:<asp:TextBox ID="TxtHDate1" runat="server"
Width="75px"></asp:TextBox>~<asp:TextBox ID="TxtHDate2" runat="server" Width="83px"></asp:TextBox>
是否結案:<asp:DropDownList ID="DdlChk" runat="server">
</asp:DropDownList>
訂單狀態:<asp:DropDownList ID="DdlState" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="查詢" /></td>
</tr>
<tr>
<td style="width:94%; vertical-align: middle; text-align: center;height: 18px;"></td>
</tr>
<tr>
<td style="width:94%; vertical-align: top; text-align: left;">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
BorderStyle="Ridge" BorderWidth="2px" DataSourceID="SqlDataSource1" PageSize="8" OnRowDataBound="GridView1_RowDataBound" OnPageIndexChanged="GridView1_PageIndexChanged" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnSelectedIndexChanging="GridView1_SelectedIndexChanging">
<Columns>
<asp:CommandField ShowSelectButton="True">
<ItemStyle Wrap="False" />
</asp:CommandField>
<asp:ButtonField ButtonType="Image" Text="我知道了" />
<asp:BoundField DataField="訂單號碼" HeaderText="訂單號碼" ReadOnly="True" SortExpression="訂單號碼">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="序號" HeaderText="序號" SortExpression="序號">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="客戶" HeaderText="客戶" SortExpression="客戶">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="接單日期" HeaderText="接單日期" SortExpression="接單日期">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="工廠交期" HeaderText="工廠交期" SortExpression="工廠交期">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="希望交期" HeaderText="希望交期" SortExpression="希望交期">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="貨櫃尺寸" HeaderText="貨櫃尺寸" SortExpression="貨櫃尺寸">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="結關日" HeaderText="結關日" SortExpression="結關日">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="備註" HeaderText="備註" SortExpression="備註" >
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="qc備註" HeaderText="qc備註" SortExpression="qc備註" >
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="修改備註" HeaderText="修改備註" SortExpression="修改備註" >
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="備料" HeaderText="備料" SortExpression="備料" >
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="是否結案" HeaderText="結案" SortExpression="是否結案">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
</Columns>
<SelectedRowStyle BackColor="Blue" ForeColor="White" />
<HeaderStyle BackColor="Black" ForeColor="White" />
<AlternatingRowStyle BackColor="#CCCCCC" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:smartERPIIRemoteConnectionString %>"
SelectCommand="up_OrdList" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="TxtIOrdNo" ConvertEmptyStringToNull="False" Name="iordno"
PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="DdlCusNo" Name="cusno" PropertyName="SelectedValue"
Type="String" />
<asp:ControlParameter ControlID="TxtHDate1" Name="hdate1" PropertyName="Text" Type="DateTime" />
<asp:ControlParameter ControlID="TxtHDate2" Name="hdate2" PropertyName="Text" Type="DateTime" />
<asp:ControlParameter ControlID="DdlChk" Name="chk" PropertyName="SelectedValue"
Type="String" />
<asp:ControlParameter ControlID="DdlState" Name="state" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
</center>
<iframe id="frameNavigation" frameborder="0" runat ="server" ></iframe>
</div>
</asp:Content>在父ASPX中的GRIDVIEW1選擇事件中做如下的操作的:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{ frameNavigation.Attributes["src"] = "frmMakeScheduleDetail.aspx?iordno=" + ((GridView)sender).SelectedRow.Cells[2].Text;
}