javascript網頁對話方塊參數詳解

來源:互聯網
上載者:User
N.1 基本介紹:

    * showModalDialog() (IE 4+ 支援),用來建立一個顯示HTML內容的模態對話方塊。
    * showModelessDialog() (IE 5+ 支援) ,用來建立一個顯示HTML內容的非模態對話方塊。

N.2 使用方法:

    * vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures])
    * vReturnValue = window.showModelessDialog(sURL [, vArguments] [,sFeatures])

N.2.1 參數說明:

    * sURL-- 必選參數,類型:字串。用來指定對話方塊要顯示的文檔的URL。
    * vArguments-- 選擇性參數,類型:變體。用來向對話方塊傳遞參數。傳遞的參數類型不限,包括數組等。對話方塊通過window.dialogArguments來取得傳遞進來的參數。
    * sFeatures-- 選擇性參數,類型:字串。用來描述對話方塊的外觀等資訊,可以使用以下的一個或幾個,用分號“;”隔開。
         1. dialogHeight :對話方塊高度,不小於100px,IE4中dialogHeight 和 dialogWidth 預設的單位是em,而IE5中是px,為方便其見,在定義modal方式的對話方塊時,用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. 下面幾個屬性是用在HTA中的,在一般的網頁中一般不使用。
        11. dialogHide:{ yes | no | 1 | 0 | on | off }:在列印或者預覽列印時對話方塊是否隱藏。預設為no。
        12. edge:{ sunken | raised }:指明對話方塊的邊框樣式。預設為raised。
        13. unadorned:{ yes | no | 1 | 0 | on | off }:預設為no。

N.3 參數傳遞:

1.要想對話方塊傳遞參數,是通過vArguments來進行傳遞的。類型不限制,對於字串類型,最大為4096個字元。也可以傳遞對象,例如:
parent.htm

<script>...
var obj = new Object();
obj.name="51js";
window.showModalDialog("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px");
</script>

modal.htm
<script>...
var obj = window.dialogArguments
alert("您傳遞的參數為:" + obj.name)
</script>

2.可以通過window.returnValue向開啟對話方塊的視窗返回資訊,當然也可以是對象。例如:

parent.htm
<script>...
str =window.showModalDialog("modal.htm", "","dialogWidth=200px;dialogHeight=100px");
alert(str);
</script>

modal.htm

 <script> window.returnValue="http://www.51js.com"; </script>

如果直接點右上方的關閉按鈕關閉,那麼返回undefined,可用是否為null來檢測。
N.4 Firefox替代方案

Firefox 不支援showModalDialog,其實一開始是支援的,但後來發現它有安全性上的隱患,就把這個功能取消了。可使用 window.open代替,不過第三個參數要加上“modal=yes”,下面是一個樣本,被開啟的視窗修改父視窗的頁面資料,值得注意的是,對於 innerText屬性,修改後Firefox不會重新整理頁面,需要使用innerHTML 屬性:

function test2() {     var frm = window.opener;     frm.document.all["td22"].innerHTML = "abcd";     window.close(); }

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.