JS開啟視窗

來源:互聯網
上載者:User

window.open('index.htm','title','height=100,width=200,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no')  
  window.showModalDialog('index.htm','title','scrollbars=yes;resizable=no;help=no;status=no;dialogTop=25;    
  dialogLeft=0;dialogHeight=400px');  
  window.showModelessDialog('index.htm','title','scrollbars=yes;resizable=no;help=no;status=no;dialogTop=25;    
  dialogLeft=0;dialogHeight=400px');  
  'index.htm'   快顯視窗的目標檔案名  
  'title'           快顯視窗的標題  
  height             快顯視窗的高度  
  width               快顯視窗的寬度  
  top                   快顯視窗與螢幕上方的距離  
  left                 快顯視窗與螢幕左側的距離  
  toolbar=no           是否顯示工具列,如果顯示則為yes  
  menubar=no           是否顯示功能表列,如果顯示則為yes  
  scrollbars=no     是否顯示捲軸,如果顯示則為yes  
  location=no         是否顯示地址欄,如果顯示則為yes  
  status=no             是否顯示狀態列,如果顯示則為yes  
  resizable=no       是否允許改變視窗大小,如果允許則為yes

showModalDialog()、showModelessDialog()方法使用詳解  
  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)    
  </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裡是可以的。    
  -------------------------------------------    
  另外整理    
  問:    
  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&para;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。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.