一、創建模態和非模態對話框
除了alert(""); confirm(""); prompt("");之外還有
創建模態對話框:
vReturnValue = window.showModalDialog(sURL [, vFreeArgument] [, sOrnaments]);
如:window.showModalDialog("callee.htm")
創建非模態對話框:
vReturnValue = window.showModelessDialog(sURL [, vFreeArgument] [, sOrnaments]);
如:window.showModelessDialog("callee.htm")
二、控制對話框大小和位置
下面的代碼將打開一個高200px、寬800px的對話框:
window.showModalDialog('callee.htm','','dialogHeight:200px;dialogWidth:800px');
以下代碼,看看關閉居中屬性后新窗口的位置:
window.showModalDialog('callee.htm','','dialogHeight:200px;dialogWidth:800px;center:no');
三、改變對話框外觀
下面的代碼將去除上下文關聯提示圖標、不顯示狀態欄、窗口邊緣風格為凹陷:
showModelessDialog("callee.htm","","status:0;help:0;edge:sunken");
四、從父頁面頁面傳遞數據到子頁面
(一)傳遞值類型數據
在caller.htm頁面中輸入以下代碼:
<INPUT TYPE="button" VALUE="創建模態對話框" onclick="fnOpenModal()">
<br><br>
<INPUT TYPE="button" VALUE="創建非模態對話框" onclick="fnOpenModeless()">
<script language="javascript">
<!--
function fnOpenModal()
{
window.showModalDialog("callee.htm","打開了一個新模態窗口")
}
function fnOpenModeless()
{
window.showModelessDialog("callee.htm","打開了一個新非模態窗口")
}
//-->
</script>
在callee.htm頁面中輸入以下代碼:
<SCRIPT LANGUAGE="JavaScript">
<!--
alert(dialogArguments);
//-->
</SCRIPT>
(二)傳遞數組引用類型數據 (同樣可以為對象傳值)
第一種值類型數據的傳遞中,在callee.htm頁面中只能讀取caller.htm頁面的傳遞數據。
當需要對caller.htm頁面的傳遞內容進行修改時,就需使用到數組引用類型的傳遞方式。
首先,在caller.htm頁面中輸入以下代碼:
<INPUT TYPE="button" VALUE="創建模態對話框" onclick="fnOpenModal()">
<br><br>
<INPUT TYPE="button" VALUE="創建非模態對話框" onclick="fnOpenModeless()">
<script language="javascript">
<!--
var a = new Array;
a[0]="first";
a[1]="second";
a[2]="third";
function fnOpenModal()
{
window.showModalDialog("callee.htm",a)
}
function fnOpenModeless()
{
window.showModelessDialog("callee.htm",a)
}
// -->
</script>
然后在callee.htm頁面中輸入以下代碼:
<SCRIPT LANGUAGE="JavaScript">
<!--
a = dialogArguments; //特殊關鍵字,表示接收的的參數對象
alert(a);
a[0] = "fourth";
// -->
</SCRIPT>
