如何在iframe所在页面操作Iframe的src文件

luofuxian 2009-05-07 03:53:30
a.aspx的html:
<div><iframe src="b.aspx"></iframe></div>

b.aspx的html:
<form id="form1" runat="server">
<asp:Panel ID="Panel1" runat="server" HorizontalAlign="Left"
Style="text-align:left; OVERFLOW-Y: auto;left: 0px; position: relative; top: 0px; SCROLLBAR-SHADOW-COLOR: #ecf2f9; SCROLLBAR-DARKSHADOW-COLOR: #99ccff; SCROLLBAR-FACE-COLOR: #ecf2f9; border-width:1px">
<asp:DataList ID="DLisselect" runat="server" Width="100%" OnItemDataBound="DLisselect_ItemDataBound" RepeatColumns="2" RepeatDirection="Horizontal">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0" width="100%"
style="background-color:#C5D4F1;text-align:left; border:solid 1px #C5D4F1; padding:2px 2px 0px 2px; font-size:12px;">
<tr style="background-color:#f9f9f9; height:18px">
<td align="center" style="width:100px">序号</td>
<td align="left" style="width:150px">列名</td>
<td align="center">选择</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:#ffffff;">
<td align="center" style="width:100px"><asp:Label ID="LBcolid" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"orderid") %>'></asp:Label></td>
<td align="left" style="width:150px"><%#DataBinder.Eval(Container.DataItem,"colalias") %></td>
<td align="center"><asp:CheckBox ID="CBisselect" runat="server"/></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr style="background-color:#ffffff;">
<td style="width:100px"></td>
<td style="width:150px"></td>
<td></td>
</tr>
</table>
</FooterTemplate>
</asp:DataList>
</asp:Panel>
<div style="margin-top:10px;">
<asp:Button ID="BtnSave" runat="server" Text="保存条件" OnClick="BtnSave_Click" />
</div>
</form>
b.aspx.cs的codebehind:
单击“保存条件”button执行的事件:
protected void BtnSave_Click(object sender, EventArgs e)
{
CheckBox cbselect = null;
for (int i = 0; i < this.DLisselect.Items.Count; i++)
{
cbselect = this.DLisselect.Items[i].FindControl("CBisselect") as CheckBox;
if (cbselect != null && cbselect.Checked == true)
dtColumn.Rows[i]["isselect"] = true;
else
dtColumn.Rows[i]["isselect"] = false;
}
dtColumn = XQuery.SetOrderID(dtColumn);
if ((!string.IsNullOrEmpty(Login_id)) && (!string.IsNullOrEmpty(Query_no)))
bllxq.BuildQueryPersonal(dtColumn, Login_id, Query_no);
}
问题描述:我想在是想的效果是:我想在a.aspx里面设置一个button来激发和b.aspx里面的"保存条件"button一样的效果。
1、这种效果可以实现吗?怎么实现?
2、如果不能实现,那能有其他办法实现吗?高人指点下,感激不尽。
...全文
281 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ayymbirst 2009-05-07
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 hdt 的回复:]
var frame = document.getElementById("frmaeid");
var win = frame.contentWindow;//frame window对象
var doc = win.document //document对象
var buid= doc.getElementByid("buttonid")//button
buid.click();
[/Quote]

比较好的方案。

当通过 document.getElementById("iframeID") 获得iframe对象(ifr)时
可通过 该对象的 ifr.contentWindow 属性 获得iframe对象的document。
,在 document对象中获得按钮对象,之后直接调用该按扭的click 。
luofuxian 2009-05-07
  • 打赏
  • 举报
回复
window.frames["iframe_ID"].document.getElementById("BtnSave").click();
没错,我自己写错了ID,IE下是对可以,在firefox下就不管用了
gelongking 2009-05-07
  • 打赏
  • 举报
回复
这个是对的· ·哈哈!~
luofuxian 2009-05-07
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 harderLi 的回复:]
能说说您想干吗么 为什么不把b.aspx整个放上去  单独独立出一个按钮干吗
[/Quote] 要这样一种效果,简单点就这么说,好求教高手!
harderLi 2009-05-07
  • 打赏
  • 举报
回复
能说说您想干吗么 为什么不把b.aspx整个放上去 单独独立出一个按钮干吗
luofuxian 2009-05-07
  • 打赏
  • 举报
回复
window.frames["iframe_ID"].document.getElementById("BtnSave").click();

这样写有错误,经过测试:window.frames["iframe_ID"].document 这里是对的,可以取到对象,
这里就取不到了: window.frames["iframe_ID"].document.getElementById("BtnSave")有写错了吗?
蓝海D鱼 2009-05-07
  • 打赏
  • 举报
回复
a.aspx的html:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="a.aspx.cs" Inherits="iframe_a" %>

<!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 runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function clickb()
{
window.frames["iframe_ID"].document.getElementById("BtnSave").click();

}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div> <iframe id="iframe_ID" src="b.aspx"> </iframe> </div>

</div>
<input id="Button1" type="button" onclick="clickb()" value="button" />
</form>
</body>
</html>




iframe 父窗口和子窗口的调用方法2006-11-28 15:15父窗口调用子窗口
iframe_ID.iframe_document_object.object_attribute = attribute_value
例子
onClick="iframe_text.myH1.innerText='http://www.pint.com';"
子窗口调用父窗口
parent.parent_document_object.object_attribute = attribute_value
例子
onclick="parent.myH1.innerText='http://www.pint.com';"

上面在IE下没有问题,但在firefox下不正常。在firefox下,应该是
父窗口调用子窗口
window.frames["iframe_ID"].document.getElementById("iframe_document_object"­).object_attribute = attribute_value
例子
window.frames["iframe_text"].document.getElementById("myH1").innerHTML= "http://www.pint.com";
子窗口调用父窗口
parent.document.getElementById("parent_document_object").object_attribute = attribute_value
例子
parent.document.getElementById("myH1").innerHTML = "http://www.adsf.com";

test.htm里面firefox下访问iframe 必须用name,不能用id
所以要改为name="iframe_test"

完整的例子
test.htm

<HTML>
<HEAD>
<TITLE> Test Page </TITLE>
<script src="prototype-1.4.0.js"></script>
<script language="javascript">
function show(){
window.frames["iframe_text"].document.getElementById("myH1").innerHTML
= "http://www.pint.com";

}
</script>
</HEAD>
<BODY>
<iframe height="350" width="600" src="iframe_text.htm"
name="iframe_text"></iframe>
<form action="" method="post">
<input name="haha" id="haha" type="text" maxlength="30" value="haha"
/><br />
<textarea cols="50" rows="5" id="getAttributeMethod"></textarea>
<input type="button" onClick="show();" value="提交"/>
</form>
<h1 id="myH1">d</h1>
</BODY>
</HTML>

frame_test.htm
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
function show(){
parent.document.getElementById("myH1").innerHTML =
"http://www.adsf.com";

}

</script>
<body>
<h1 id="myH1">ha</h1>
<form action="" method="post">
<input name="abc" id="abc" type="text" maxlength="30" value="abc" /><br
/>
<textarea cols="50" rows="10" id="text"></textarea> <br />
<input type="button" value="提交" onclick="show();"/>
</form>
</body>
</html>

真相重于对错 2009-05-07
  • 打赏
  • 举报
回复
var frame = document.getElementById("frmaeid");
var win = frame.contentWindow;//frame window对象
var doc = win.document //document对象
var buid= doc.getElementByid("buttonid")//button
buid.click();
阿非 2009-05-07
  • 打赏
  • 举报
回复
用js操作就可以了

找到iframe中对应的button 调用它的click方法
vlysses 2009-05-07
  • 打赏
  • 举报
回复
a.aspx代码大概是这样:

<iframe name="iframe1" src=""> </iframe>
<input type="button" id="btn1" onclick="javascript:iframe1.src='b.aspx?save=1';">


b.aspx.cs代码:

void page_load()
{
if(!IsPostBack)
{
if(Request.QureyString["save"]!=null)
DoSave();
}
}
private void DoSave()
{
CheckBox cbselect = null;
for (int i = 0; i < this.DLisselect.Items.Count; i++)
{
cbselect = this.DLisselect.Items[i].FindControl("CBisselect") as CheckBox;
if (cbselect != null && cbselect.Checked == true)
dtColumn.Rows[i]["isselect"] = true;
else
dtColumn.Rows[i]["isselect"] = false;
}
dtColumn = XQuery.SetOrderID(dtColumn);
if ((!string.IsNullOrEmpty(Login_id)) && (!string.IsNullOrEmpty(Query_no)))
bllxq.BuildQueryPersonal(dtColumn, Login_id, Query_no);

}

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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