现在的位置: 首页 > 综合 > 正文

跨IE窗体操作

2013年05月20日 ⁄ 综合 ⁄ 共 1843字 ⁄ 字号 评论关闭

跨IE窗体的操作有多种实现方法。

方法1、如果跨越的窗体是框架的,那么可以直接用框架的名称进行操作:
在我的 《ifream中的数据传递》 中提到过
不过如果是用框架集的话,需要使用到 frames 集合,并使用其索引来指定操作对象是哪一个窗体
如:top.frames[0].document.all.f1.value;

方法2、模态窗口的操作
通过获取模态窗口的返回值实现

主页窗口


 

<script>

function openmodel()
{
 var k;
 k=window.showModalDialog("model.htm");
 if(k!=null)
 {
 alert(k);
 }
 else
 {
 window.location.reload();
 }

}

</script>
<body>
<input type="button" value="打开模态" onClick="openmodel()">

</body>

模态窗口


<body>
<script>
window.returnValue='aa';
</script>
<input type="button" value="关闭" onClick="window.close();">
</body>

 

 

方法3、主窗口与被打开窗口的操作:
我在一个窗体1中用window.open打开一个新窗体2,我要在新窗体2的的按钮按下后,能把输入的信息传给窗体1使窗体1的页面更新,应该怎么做?

你试试下面的代码:
<input type=button value="刷新父窗口" onclick="opener.reload();">


父窗口如下所示:
parent.htm
-------------
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Name</title>
</head>
<body>
<form method="POST" action="--WEBBOT-SELF--">
<p>Name:<input type="text" name="name" size="20"><br>
Age:<input type="text" name="age" size="20"><input type="button" value="打开子窗口" name="B3" onclick="window.open('children.htm','test');"></p>
</form>
</body>
</html>

 

子窗口如下所示:
children.htm
----------------
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Name</title>
</head>
<body>
<form method="POST" action="--WEBBOT-SELF--">
<p>
Name:<input type="text" name="name" size="20"><br>
Age:<input type="text" name="age" size="20">
<input type="button" value="传给父窗口" name="B3" onclick="opener.document.all.name.value=document.all.name.value;opener.document.all.age.value=document.all.age.value;"></p>
</form>
</body>
</html>
你可以根据你的需要适当的调整。

抱歉!评论已关闭.