標籤:工作列 關閉視窗 客戶機 replace https 擷取 top 螢幕寬度 高度
1.window對象
/*1.計算瀏覽器視窗大小*/ //不算捲軸: var width = window.innerWidth; var height = window.innerHeight; document.write("瀏覽器視窗寬度:"+width+",瀏覽器視窗高度:"+height+"<br/>"); //算捲軸: var outerWidth = window.outerWidth; var outerHeight = window.outerHeight; document.write("外部瀏覽器視窗寬度:"+outerWidth+",外部瀏覽器視窗高度:"+outerHeight+"<br/>"); /*2.開啟新視窗*/ function openWin(){ window.open("http://www.baidu.com","MyWindow","width=300,height=200,left=50,top=100") } function openWin(){ var myW = window.open("xxx.html","MyWindow","width=300,height=200,left=50,top=100"); myW.document.write("這是一個新視窗"); } /*3.關閉視窗*/ function closeWin(){ window.close(); } /*4.列印*/ function printWin(){ window.print(); } 2.Screen對象
window.screen對象在編寫的時候可以不使用window首碼。
/*1.擷取螢幕寬高*/ //可用螢幕寬度(不包括工作列等) var availWidth = screen.availWidth; //可用螢幕高度(不包括工作列等) var availHeight = screen.availHeight; document.write("螢幕可用寬度:"+availWidth+",螢幕可用高度:"+availHeight+"<br/>"); //螢幕總寬度(包括工作列) var screenWindh = screen.width; //螢幕總高度(包括工作列) var screenHeight = screen.height; document.write("螢幕總寬度:"+screenWindh+",螢幕總高度:"+screenHeight+"<br/>");3.Location對象
window.location對象在編寫的時候可以不使用window首碼。
Location對象的屬性:
1)返回完整URL:location.href
2)返回一個URL的主機名稱和連接埠:location.host
3)返回URL的主機名稱:location.hostname
4)返回web主機的連接埠(80或443):location.port
5)返回所使用的web協議(http://或https://):location.protocol
Location對象的方法:
/*1.重新載入新的頁面*/ function assignNew(){ window.location.assign("http://www.baidu.com"); } /*2.重新載入當前頁面*/ function reloadCur(){ window.location.reload(); } /*3.替換新的頁面*/ function replaceNew(){ window.location.replace("http://www.baidu.com"); }4.History對象
提供一些訪問曆史資訊的屬性和方法。
屬性:
history.length:返回歷史列表中的網頁數。
方法:
/*1.前進一個頁面*/ function forwardPage(){ window.history.forward(); } /*2.回退到前一個頁面*/ function backPage(){ window.history.back(); } /*3.前進n頁*/ function goPage(){ window.history.go(1);//記錄後一頁是1,前一頁是-1 }5.Navigator對象
navigator對象包含有關瀏覽器的資訊
屬性:
1)appCodeName:瀏覽器代碼名
2)appName:瀏覽器名稱
3)appVersion:瀏覽器平台和版本資訊
4)cookieEnabled:瀏覽器是否啟用cookie
5)platform:運行瀏覽器的作業系統平台
6)userAgent:返回有客戶機發送伺服器的user-agent頭部的值
需要注意,來自navigator對象的資訊具有誤導性,不應該用於檢測瀏覽器版本,這是因為:
- navigator資料可被瀏覽器使用者更改
- 一些瀏覽器對測試網站會識別錯誤
- 瀏覽器無法報告晚於瀏覽器發布的新作業系統
js瀏覽器對象的屬性和方法