javascript中的window對象

來源:互聯網
上載者:User
 轉]Window視窗對象2009-10-15 09:33

一 window屬性

1、獲得當前視窗的對象:window.frameElement

var frameObj = window.frameElement;

獲得當前視窗的名字:frameObj.name

獲得當前視窗的架構的數量:frameObj.length

獲得當前視窗的架構靈數組:frameObj.frames 其本身也是一個對象,也具有length屬性

2、獲得當前視窗的曆史列表

var historyObj = window.history;

history.length 當前瀏覽器訪問過的頁面的數量

history.back()   相當於[上一頁] 按鈕

history.forward() 相當於“前進”按鈕

history.go()     頁面 跳轉,參數為正向後跳轉,參數為負向前跳轉,參數為0重新載入當前頁面

3、獲得某個視窗的URL資訊 window.location

可以通過指定location 屬性值將頁面跳轉至指定的地址

如果在本機,可以通過指定此屬性的值為相對路徑,跳轉至另一個檔案

4 獲得開啟視窗的原視窗或架構對象 opener

var openObj = window.opener;

openObj.length

openObj.name

openObj.frames

5 獲得當前頁面的父架構或視窗對象

var parentObj = window.parent;

parentObj.frames[下標]    parent.frames[架構名] 父架構所有的子架構

6 獲得當前架構的最頂層視窗

var topObj = window.top;

7 視窗狀態條資訊

window.defaultStatus 預設顯示的(即使用者開啟視窗時顯示的)

window.status 動態顯示

8、螢幕資訊的擷取

網頁可見地區寬: document.body.clientWidth;
網頁可見地區高: document.body.clientHeight;
網頁可見地區寬: document.body.offsetWidth (包括邊線和捲軸的寬)”;
網頁可見地區高: document.body.offsetHeight (包括邊線的寬)”;
網頁本文全文寬: document.body.scrollWidth;
網頁本文全文高:document.body.scrollHeight;
網頁被捲去的高(ff): document.body.scrollTop;
網頁被捲去的高(ie):document.documentElement.scrollTop;
網頁被捲去的左: document.body.scrollLeft;
網頁本文部分上:window.screenTop;
網頁本文部分左:window.screenLeft;
螢幕解析度的高:window.screen.height (常用)
螢幕解析度的寬:window.screen.width    (常用)
螢幕可用工作區高度:window.screen.availHeight;
螢幕可用工作區寬度: window.screen.availWidth;
螢幕位彩色設定 window.screen.colorDepth

螢幕像素/英寸設定   window.screen.deviceXDPI

二 window方法

1 、訊息框

window.alert()

2 、確認對話方塊

window.confirm()    確定按鈕返回“true”,取消按鈕返回“false”

3 、輸入對話方塊

window.prompt("顯示的提示資訊","輸入的預設值")

確定按鈕:如果輸入了值,則返回輸入的資訊;如果沒有輸入資訊,也沒有預設值,返回空串

取消按鈕:返回null

4、開啟一個新視窗

var win = window.open("url","winName","param");

url 目標視窗的URL地址

winName

(1)視窗名稱

(2)內建名稱:

_self   在提交表單最所使用的視窗開啟目的文件

_parent 在顯示當前文檔的父視窗中打工文檔

_blank 開啟一個新視窗

_top 在當前視窗內開啟目的文件,確保目的文件佔用整個視窗

param :開啟視窗的參數

(1)toolbar 是否顯示工具列   值為:yes/no    1/0

(2)location 視窗是否顯示地址    值為:yes/no 1/0

(3)directories 視窗是否顯示連結工具列

(4)status 是否顯示狀態列

(5)menubar 是否顯示功能表列

(6)scrollbars 是否顯示捲軸

(7)resizable 視窗大小是否可改變

(8)top 視窗距螢幕頂端的位置 單位:像素

(9)left 視窗距螢幕左邊的位置

(10)width 視窗的寬度

(11)height 視窗的高度

5、把焦點從視窗移開

window.blur()

6、讓指定的視窗獲得焦點

window.focus()  

7、關閉視窗

window.close()

8、延時

var timeID=window.setTimeout(funName,millisec)

funName 要執行的函數名

millisec 時間間隔

反覆執行可以用遞迴,還可以用window的另一個方法

var timeID=window.setInterval("funName","millisec")

終止延時

window.clearTimeout(timeID)

其中timeID就是setTimeout的傳回值

類似的還有clearTimeout(timeID)

相關文章

聯繫我們

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