在云那方

首页 新随笔 联系 订阅 管理

window.open ('page.html','','height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
            var getv = window.showModalDialog("log.htm", "", "dialogWidth:420px; dialogHeight:220px;status:no;help:yes");

window.open是打开新窗口

window.showModalDialog(URL,dialogArgments.features) 打开一个新窗口
URL为要开启的网页。
dialogArgments为设定好传递给新视窗网页的参数,可以为任意数据类型。
feature 与open()的类似,都是格式方面的设定。调用格式为featureName1:featureValue1:(分号)featureName2:featureValue2:
certer , dialogHeight, dialogLeft,dialogTop,dialogWidth,help(是否显示help按钮,下同),status,resizeable
值=1为yes,0为no.

我认为最重要的是dialogArgments,可以传递值到新的窗口。
第二重要就是 它的返回值 window.returnValue.可以在showModalDialog开启的窗口关闭后前,回传一个任意类型的值


showModalDialog帮助可以参阅微软MSDN http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/showmodaldialog.asp
AA.HTM

--------------------------------------------------------------------------------------------------------------------------
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>主界面</title>
</head>

<body>
<form id="getForm">    回传值:<input type="text" id="getData" readOnly> <input type="text" id="getData1" readOnly>

</form>
<input type="button" value="打开新窗口1" onClick="openWin1()">
<input type="button" value="打开新窗口2" onClick="openWin2()">
<script language="JavaScript">   
function openWin1()   
{       
var srcFile = "BB.htm";    //新窗口的文档名称       
var winFeatures = "dialogHeight:300px; dialogLeft:200px;";       
var obj = getForm; //将form作为对象传递给新窗口              
window.showModalDialog(srcFile, obj, winFeatures);   
}
function openWin2()   
{       
var srcFile = "CC.htm";    //新窗口的文档名称       
var winFeatures = "dialogHeight:300px; dialogLeft:200px;";       
var obj = getForm.getData.value; //将form作为对象传递给新窗口              
var str=window.showModalDialog(srcFile, obj, winFeatures);   
if(str!=null)
     document.getForm.getData.value = str;
}

</script>

</body>

</html>

BB.HTM
重要提示:你弹出窗口中调用的是ASPX文件时,必须在Page_Load事件中加入以下代码
Response.Expires = 0; Response.Cache.SetNoStore(); Response.AppendHeader("Pragma", "no-cache");
否则,每次弹出的页面都是上一次的Cache,不会改变。

------------------------------------------------------------------------------------------------------------------------
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新窗口BB</title>
</head>

<base target="_self"> <!--这句话非常重要,只要加上才能保证在弹出窗口中调用服务端代码而不会再弹出一个新窗口-->
<body>
<form id="sendForm">    请输入资料:
<input type="text" id="writeData">   
<input type="text" id="writeData1">
<input type="button" value="送回父窗口" onClick="send(sendForm.writeData.value,sendForm.writeData1.value);">
</form>
<script language="JavaScript">   
function send(val,val1)   
{       
    //取得父窗口传过来的对象       
    var myObj = window.dialogArguments;       
    //赋值
    myObj.getData.value = val;
    myObj.getData1.value = val1;
    //关闭窗口       
    window.close();   
}
</script>

</body>

</html>

CC.HTM
------------------------------------------------------------------------------------------------------------------------
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新窗口CC</title>
</head>

<base target="_self"> <!--这句话非常重要,只要加上才能保证在弹出窗口中调用服务端代码而不会再弹出一个新窗口-->
<body>
<form id="sendForm">    请输入资料:
<input type="text" id="writeData">   
<input type="button" value="送回父窗口" onClick="send(sendForm.writeData.value);">
</form>
<script language="JavaScript">   
function send(val)   
{        
    window.returnValue=val
    window.close();   
}
</script>

</body>

</html>

posted on 2008-07-04 11:05  Rich.T  阅读(508)  评论(0编辑  收藏  举报