parent.html
<script>
var modelessDialog,modalDialog;
function showPage1(pageSrc)
{
modalDialog = window.showModalDialog(pageSrc,window.document,"dialogWidth=600px;dialogHeight=500px");
if(modalDialog != "")
{
document.getElementById("txtUserName").value = modalDialog;
}
}
function showPage2(pageSrc)
{
modelessDialog = window.showModelessDialog(pageSrc,window.document,"dialogWidth=600px;dialogHeight=500px");
}
function showPage3(pageSrc)
{
///需要注意弹出的窗口没有脚本阻止
popupWindow=window.open(pageSrc,'A','width=300,height=500,scrollbar=yes,titlebar=no,toolbar=no,menubar=no');
window.popupWindow.focus();
}
function showPage4(pageSrc)
{
if(modelessDialog == null)
{
modelessDialog = window.showModelessDialog(pageSrc,window.document,"dialogWidth=600px;dialogHeight=500px");
}
else
{
try
{
modelessDialog.focus();
}
catch(e)
{
modelessDialog = window.showModelessDialog(pageSrc,window.document,"dialogWidth=600px;dialogHeight=500px");
}
}
}
</script>
<input type="text" id="txtUserName" value="输入你的名字" onMouseMove="this.select();"><br>
<input type="Button" value="弹出窗口(独占方式)" onClick="showPage1('Open1.htm');"><br>
<input type="Button" value="弹出窗口(非独占方式)" onClick="showPage2('Open1.htm');"><br>
<input type="Button" value="弹出窗口(Open方式,点N次只弹出一个窗口)" onClick="showPage3('Open1.htm');"><br>
<input type="Button" value="弹出窗口(非独占方式,点N次只弹出一个窗口)" onClick="showPage4('Open1.htm');"><br>
<a href="Open1.htm" target="onlyone">只会弹出一次的链接</a>
***************************************************
Open1.htm
<script language="javascript">
var doc = window.dialogArguments;
function writeParent()
{
if(doc != null)
{//窗口是 ModalDialog 打开的
doc.getElementById("txtUserName").value= document.getElementById("txtUserName").value;
}
else
{
//窗口是 Open 方式打开的
window.opener.document.getElementById("txtUserName").value= document.getElementById("txtUserName").value;
}
}
///关闭并且返回值给父窗体
function closeAndReturn()
{
if(doc != null)
{
window.returnValue = "从子窗体返回的值";
}
window.close();
}
///刷新父窗体
function refreshParent()
{
alert("a");
if(doc != null)
{
alert(doc);
doc.location.reload();
}
alert("b");
}
</script>
AAA
<input type="text" id="txtUserName" value="" onchange="writeParent();"><br>
<input type="button" value="Set Parent Value" onClick="writeParent();"><br>
<input type="button" value="Close and return value" onClick="closeAndReturn();"><br>
<input type="button" value="Refresh Parent Window" onClick="refreshParent();"><br>
1.下面是取消客户端缓存的: <br>
<meta http-equiv="Expires" CONTENT="0"><br>
<meta http-equiv="Cache-Control" CONTENT="no-cache"><br>
<meta http-equiv="Pragma" CONTENT="no-cache"><br>
4.在子窗口中若要提交页面的话要加入:,这样就不会打开新窗口了.<br>
<head><br>
<base target="_self"><br>
</HEAD><br>
</HtmlEncode>