使用環境:
showModalDialog IE4以上版本
showModelessDialog IE5以上
區別:
showModalDialog 被開啟後就會始終保持輸入焦點。無法操作主視窗,除非關閉對話方塊。
showModelessDialog 被開啟後,使用者可以隨機切換輸入焦點。只是主視窗被對話方塊擋住。
使用方法:
vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures])
vReturnValue = window.showModelessDialog(sURL [, vArguments] [,sFeatures])
參數說明:
sURL 必選參數,類型:字串。用來指定對話方塊要顯示的文檔的URL。
vArguments 選擇性參數,類型:變體。用來向對話方塊傳遞參數。傳遞的參數類型不限,包括數組等。對話方塊通過window.dialogArguments來取得傳遞進來的參數。
sURLsFeatures 選擇性參數,類型:字串。用來描述對話方塊的外觀等資訊,可以使用以下的一個或幾個,用分號“;”隔開。
1.dialogHeight 對話方塊高度,不小於100px,IE4中dialogHeight和dialogWidth 預設的單位是em,而IE5中是px
2. dialogWidth: 對話方塊寬度。
3. dialogLeft: 離螢幕左的距離。
4. dialogTop: 離螢幕上的距離。
5. center: { yes | no | 1 | 0 } : 是否置中,預設yes,但仍可以指定高度和寬度。
6. help: {yes | no | 1 | 0 }: 是否顯示協助按鈕,預設yes。
7. resizable: {yes | no | 1 | 0 } [IE5+]: 是否可被改變大小。預設no。
8. status:{yes | no | 1 | 0 } [IE5+]:是否顯示狀態列。預設為yes[ Modeless]或no[Modal]。
9. scroll:{ yes | no | 1 | 0 | on | off }:是否顯示捲軸。預設為yes。
10. dialogHide:{ yes | no | 1 | 0 | on | off }:在列印或者預覽列印時對話方塊是否隱藏。預設為no。
11. edge:{ sunken | raised }:指明對話方塊的邊框樣式。預設為raised。
12. unadorned:{ yes | no | 1 | 0 | on | off }:預設為no。
例子:
f.html
複製代碼 代碼如下:
<html>
<head>
<title>主視窗</title>
<script type="text/javascript">
<!--
var child;
function openDialogBox()
{
child = window.showModalDialog('c.html',document.all["txt"],"dialogWidth=500px;dialogHeight=200px;");
}
//-->
</script>
</head>
<body>
<input name="txt" type="text" disabled="disabled" />
<input name="btn" type="button" value="開啟對話方塊" onClick="openDialogBox();" />
</body>
</html>
c.html
複製代碼 代碼如下:
<html>
<head>
<title>對話方塊</title>
<script type="text/javascript">
<!--
function set()
{
window.dialogArguments.value=document.all["txt"].value
}
//-->
</script>
</head>
<body>
<input name="txt" type="text"/>
<input name="btn" type="button" value="設定" onClick="set();" />
</body>
</html>