模式對話框的詳細使用說明

          Posted on 2006-09-20 10:27 weibogao 閱讀(1111) 評論(0)  編輯  收藏 所屬分類: riasoftware development

          javascript有許多內建的方法來產生對話框,如:window.alert(), window.confirm(),window.prompt().等。 然而IE提供更多的方法支持對話框。如:

            showModalDialog() (IE 4+ 支持)
            showModelessDialog() (IE 5+ 支持)


          window.showModalDialog()方法用來創建一個顯示HTML內容的模態對話框,由于是對話框,因此它并沒有一般用window.open()打開的窗口的所有屬性。
          window.showModelessDialog()方法用來創建一個顯示HTML內容的非模態對話框。

          當我們用showModelessDialog()打開窗口時,不必用window.close()去關閉它,當以非模態方式[IE5]打開時, 打開對話框的窗口仍可以進行其他的操作,即對話框不總是最上面的焦點,當打開它的窗口URL改變時,它自動關閉。而模態[IE4]方式的對話框始終有焦點(焦點不可移走,直到它關閉)。模態對話框和打開它的窗口相聯系,因此我們打開另外的窗口時,他們的鏈接關系依然保存,并且隱藏在活動窗口的下面。

          使用方法如下:
          vReturnvalue = window.showModalDialog(sURL [, vArguments] [, sFeatures])
          vReturnvalue = window.showModelessDialog(sURL [, vArguments] [, sFeatures])
          參數說明:
          sURL
          必選參數,類型:字符串。用來指定對話框要顯示的文檔的URL。
          vArguments
          可選參數,類型:變體。用來向對話框傳遞參數。傳遞的參數類型不限,包括數組等。對話框通過window.dialogArguments來取得傳遞進來的參數。
          sFeatures
          可選參數,類型:字符串。用來描述對話框的外觀等信息,可以使用以下的一個或幾個,用分號“;”隔開。
          ??dialogHeight 對話框高度,不小于100px,IE4中dialogHeight 和 dialogWidth 默認的單位是em,而IE5中是px,為方便其見,在定義modal方式的對話框時,用px做單位。
            dialogWidth: 對話框寬度。
            dialogLeft: 距離桌面左的距離。
            dialogTop: 離桌面上的距離。
            center: {yes | no | 1 | 0 }:窗口是否居中,默認yes,但仍可以指定高度和寬度。
            help: {yes | no | 1 | 0 }:是否顯示幫助按鈕,默認yes。
            resizable: {yes | no | 1 | 0 } [IE5+]:是否可被改變大小。默認no。
            status: {yes | no | 1 | 0 } [IE5+]:是否顯示狀態欄。默認為yes[ Modeless]或no[Modal]。
          ??scroll:{ yes | no | 1 | 0 | on | off }:指明對話框是否顯示滾動條。默認為yes。

          ??還有幾個屬性是用在HTA中的,在一般的網頁中一般不使用。
          ??dialogHide:{ yes | no | 1 | 0 | on | off }:在打印或者打印預覽時對話框是否隱藏。默認為no。
          ??edge:{ sunken | raised }:指明對話框的邊框樣式。默認為raised。
          ??unadorned:{ yes | no | 1 | 0 | on | off }:默認為no。

          傳入參數:
          要想對話框傳遞參數,是通過vArguments來進行傳遞的。類型不限制,對于字符串類型,最大為4096個字符。也可以傳遞對象,例如:

          test1.htm
          ====================
          <script>
          ??var mxh1 = new Array("mxh","net_lover","孟子E章")
          ??var mxh2 = window.open("about:blank","window_mxh")
          ??// 向對話框傳遞數組
          ??window.showModalDialog("test2.htm",mxh1)
          ??// 向對話框傳遞window對象
          ??window.showModalDialog("test3.htm",mxh2)
          </script>

          test2.htm
          ====================
          <script>
          ??var a = window.dialogArguments
          ??alert("您傳遞的參數為:" + a)
          </script>

          test3.htm
          ====================
          <script>
          ??var a = window.dialogArguments
          ??alert("您傳遞的參數為window對象,名稱:" + a.name)
          </script>

          可以通過window.returnvalue向打開對話框的窗口返回信息,當然也可以是對象。例如:

          test4.htm
          ===================
          <script>
          ??var a = window.showModalDialog("test5.htm")
          ??for(i=0;i<a.length;i++) alert(a[i])
          </script>

          test5.htm
          ===================
          <script>
          function sendTo()
          {
          ??var a=new Array("a","b")
          ??window.returnvalue = a
          ??window.close()
          }
          </script>
          <body>
          <form>
          ??<input value="返回" type=button onclick="sendTo()">
          </form>

          常見問題:
          1,如何在模態對話框中進行提交而不新開窗口?
          如果你 的 瀏覽器是IE5.5+,可以在對話框中使用帶name屬性的iframe,提交時可以制定target為該iframe的name。對于IE4+,你可以用高度為0的frame來作:例子,

          test6.htm
          ===================
          <script>
          ??window.showModalDialog("test7.htm")
          </script>

          test7.htm
          ===================
          if(window.location.search) alert(window.location.search)
          <frameset rows="0,*">
          ??<frame src="about:blank">
          ??<frame src="test8.htm">
          </frameset>

          test8.htm
          ===================
          <form target="_self" method="get">
          <input name=txt value="test">
          <input type=submit>
          </form>
          <script>
          if(window.location.search) alert(window.location.search)
          </script>
          2,可以通過http://servername/virtualdirname/test.htm?name=mxh方式直接向對話框傳遞參數嗎?
          答案是不能。但在frame里是可以的。

          -------------------------------------------
          另外:
          http://www.csdn.net/
          本人整理

          問:
          1.模態窗口的打開
          2.模態窗口的關閉
          3.模態窗口的傳遞參數。
          4.其他。。。。

          hgknight(江雨.net)答:
          1.window.showModalDialog("DialogPage.aspx","newwin","dialogHeight: 200px; dialogWidth: 150px; dialogTop: 458px; dialogLeft: 166px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;");

          2.window.close();

          3.傳值
          ParentPage.aspx:
          window.showModalDialog("DialogPage.aspx?para1=aaa?2=bbb");

          DialogPage.aspx:
          string str1=Request.QueryString["para1"].toString();
          string str2=Request.QueryString["para2"].toString();

          返回值
          DialogPage.aspx:
          window.returnvalue="aaa";

          ParentPage.aspx:
          var str=window.showModalDialog("DialogPage.aspx");

          4.
          aspx頁面在showmodeldialog情況下為什么一提交就重新打開一個頁面?
          showmodaldialog打開的頁面中在<head></head>之間加入一行:<base target="_self">
          --------------------------------------------
          snowjin78(方圓)
          以前,我也問過此類問題,現把收獲貼如下(當然好多東西都是別人告訴我的):
          最好不要用Response.Write(??"??<script....??</script??>??")這樣的方法注冊客戶端腳本,而應該用Page.RegisterStartupScript或Page.RegisterClientScriptBlock方法來注冊.
          Page.RegisterClientScriptBlock:??
          在??Page??對象的????<form??runat=??server??>??元素的開始標記后立即發出客戶端腳本??
          Page.RegisterStartupScript:??
          該方法在??Page??對象的????<form??runat=??server??>??元素的結束標記之前發出該腳本

          客戶端代碼有兩個問題,第一是把window寫成了Window,javascript是嚴格區分大小寫的,用Window是肯定會出錯的;第二個問題是設置對話框的寬度用dialogWidth,高度用dialogHeight,而不是height和width。!

          posts - 41, comments - 7, trackbacks - 0, articles - 0

          Copyright © weibogao

          主站蜘蛛池模板: 景东| 自治县| 唐海县| 高陵县| 阳东县| 长治县| 长乐市| 鄄城县| 聊城市| 英德市| 平乐县| 阜康市| 长治市| 任丘市| 时尚| 徐州市| 东乌| 尼木县| 钟祥市| 常山县| 桑日县| 牟定县| 东海县| 延安市| 土默特右旗| 腾冲县| 凤阳县| 永德县| 开鲁县| 全州县| 宁武县| 浦城县| 筠连县| 灵寿县| 响水县| 上饶市| 新邵县| 麻城市| 岳阳县| 恩施市| 偃师市|