欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript Window 打開新窗口(window.location.href、window.open、window.showModalDialog)

 更新時(shí)間:2023年05月09日 15:23:54   作者:xuefeng_210  
本文主要介紹了JavaScript Window 打開新窗口的三種方式,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

1、方式1: window.location.href

window.location.href="http://www.dbjr.com.cn";     //在當(dāng)前窗口中打開窗口

類似于HTML:

<a href="http://www.dbjr.com.cn" title="測試1">Welcome Test1</a>

2、方式2: window.open

window.open("http://www.dbjr.com.cn");      //在另外新建窗口中打開窗口

類似于HTEL:

<a href="http://www.dbjr.com.cn" title="測試2" target="_blank">Welcome Test2</a>

指定參數(shù):

<script >
  var NewUrl = 'www.baidu.com' ;      
  window.open(NewUrl,'newindow','height=600,width=900,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');
</script > 

參數(shù)說明:

  • NewUrl  //' 彈出窗口的地址; 
  • 'newwindow'   //彈出窗口的名字,非必須,可用空''代替; 
  • height=600 //窗口高度; 
  • width=900 //窗口寬度; 
  • top=0 //窗口距離屏幕上方的象素值; 
  • left=0 //窗口距離屏幕左側(cè)的象素值; 
  • toolbar=no //是否顯示工具欄,yes為顯示; 
  • menubar,scrollbars //表示菜單欄和滾動欄。 
  • resizable=no //是否允許改變窗口大小,yes為允許; 
  • location=no //是否顯示地址欄,yes為允許; 
  • status=no //是否顯示狀態(tài)欄內(nèi)的信息,yes為允許;    

3、方式3 window.showModalDialog (部分瀏覽器不支持)

var URL='http://www.dbjr.com.cn'
window.showModalDialog(URL,'','DialogLeft:170px;DialogTop:130px;DialogWidth:930px;DialogHeight:753px;status:no;help:no');

原型:

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

參數(shù)說明:

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

另外幾個(gè)屬性用在HTA中的,在一般的網(wǎng)頁中一般不使用。

  • dialogHide:{ yes | no | 1 | 0 | on | off }://在打印或者打印預(yù)覽時(shí)對話框是否隱藏。默認(rèn)為no。
  • edge:{ sunken | raised }://指明對話框的邊框樣式。默認(rèn)為raised。
  • unadorned:{ yes | no | 1 | 0 | on | off }://默認(rèn)為no。

傳入?yún)?shù):

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

//test1.htm
<script>
  var mxh1 = new Array("mxh","net_lover","孟子E章")
  var mxh2 = window.open("about:blank","window_mxh")
  // 向?qū)υ捒騻鬟f數(shù)組
  window.showModalDialog("test2.htm",mxh1)
  // 向?qū)υ捒騻鬟fwindow對象
  window.showModalDialog("test3.htm",mxh2)
</script>
//test2.htm
<script>
  var a = window.dialogArguments
  alert("您傳遞的參數(shù)為:" + a)
</script>
//test3.htm
<script>
  var a = window.dialogArguments
  alert("您傳遞的參數(shù)為window對象,名稱:" + a.name)
</script>

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

//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>
<form>
  <input value="返回" type=button onclick="sendTo()">
</form>

4、Window 其他參考

  • window.open() - 打開新窗口
  • window.close() - 關(guān)閉當(dāng)前窗口
  • window.moveTo() -移動當(dāng)前窗口
  • window.resizeTo() -重新調(diào)整當(dāng)前窗口

 到此這篇關(guān)于JavaScript Window 打開新窗口的三種方式的文章就介紹到這了,更多相關(guān)JavaScript Window 打開新窗口內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論