window 物件 | it is the global object for client-side JavaScript programs. | |||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
JavaScript 程式的執行 |
|
|||||||||||||||||||||||||||||||||||||||
window 列舉
|
||||||||||||||||||||||||||||||||||||||||
![]() |
||||||||||||||||||||||||||||||||||||||||
location |
window.location === document.location 兩個location指的是同一個物件
可以加上字串在網址列再試試 : ?A=123&b=234&sn=ABCDsdf
|
|||||||||||||||||||||||||||||||||||||||
安全實現跨網域通訊 postMessage |
window.postMessagepostMessage 可以安全地實現跨網域傳遞資料或訊息,只要正確使用, 這種方法就很安全。 //來源網頁 $(document).ready(function () { //監聽 message window.addEventListener('message', function (event) { //限制來源網站為 if (event.origin.indexOf('ddmg.com.tw') != -1) { console.log(event.data); //event.data 即為目標網址傳來的資料; } }); }); function openFacebokRegister() { window.open('http://core.ddmg.com.tw/Learn/fbLogin.html','', config = 'height=500,width=500'); } //目標網頁 $(document).ready(function () { window.opener.postMessage('23k4jh2i3ut4-2k3j423k4h-sdf2342', '*'); window.close(); }); |
|||||||||||||||||||||||||||||||||||||||
history |
瀏灠歷程
|
|||||||||||||||||||||||||||||||||||||||
navigator |
早期大多用來識別瀏灠器的
|
|||||||||||||||||||||||||||||||||||||||
screen | ||||||||||||||||||||||||||||||||||||||||
Dialog Boxes對話框 |
alert('顯示訊息'); if(confirm('是否確認')) { } var str = prompt('請輸入資料') |
|||||||||||||||||||||||||||||||||||||||
onerror |
onerror 事件處理器是舊的東西, try catch 出現之後以使用 try catch 較為方便且好用 .
// Display error messages in a dialog box, but never more than 3 window.onerror = function (msg, url, line) { if (onerror.num++ < onerror.max) { alert("ERROR: " + msg + "\n" + url + ":" + line); return true; } // 回傳 false 表示已處理好錯誤 , 不需更進一步的動作 } onerror.max = 3; onerror.num = 0; |
|||||||||||||||||||||||||||||||||||||||
window 焦點 |
使用在如果有子視窗時 , 想要讓子視窗一直顯示在最上層 , 或是讓視窗移到背景
subWin= window.open(xxxxx) ==> subWin.focus( ) Or subWin.blur( ) window.blur( ) window.focus( ) |
|||||||||||||||||||||||||||||||||||||||
設定 / 解除事件 這些 IE 都不支援 |
像要針對視窗被拖曳 , 按鈕被點選等事件 , 優先進行事件處理時
window.captureEvents : 指定要取得的事件 |
|||||||||||||||||||||||||||||||||||||||
開啟 / 關閉視窗 |
|
|||||||||||||||||||||||||||||||||||||||
快顯視窗 createPopup |
只有 IE 有用, 而且新版的好像移掉了
function openNewPopup() { var wObj = window.createPopup(); var popObj = wObj.document.body; popObj.style.border = "solid 2px blue"; popObj.document.bgColor = "yellow"; popObj.innerHTML = "快顯視窗裡的內容" wObj.show(-100, 80, 400, 320, document.body); } |
|||||||||||||||||||||||||||||||||||||||
狀態列參照 / 設定 defaultStatus status |
defaultStatus -->預設狀態列的顯示內容 status -->狀態列的顯示內容
|
|||||||||||||||||||||||||||||||||||||||
setTimeout |
var setT = window.setTimeout( function () { }, 1000 * 36, {} ); // window.clearTimeout(setT); |
|||||||||||||||||||||||||||||||||||||||
setInterval |
var it = window.setInterval( function () { }, 1000 * 36, {} ); window.clearInterval(it); |
|||||||||||||||||||||||||||||||||||||||
Relationships Between Frames |
iframe 元素具有一個 contentWindow 屬性, 指的是 iframe 裡的 window物件
var win = window.open('', ''/*....*/); //回指開啟它的視窗 win.opener //來取得iframe , 而不用 getElmentById window.frames['id'] |
|||||||||||||||||||||||||||||||||||||||
視窗的高度 / 寬度
更改位置
|
1.視窗大小
window.outerWidth ; window.outerHeight ;
Netscape的用法 IE不適用 IE 用下列的方式 document.body.clientWidth + 24 document.body.clientHeight + 128 2.指定視窗大小 resizeTo( w , h ) 3.視窗移動到 window.moveTo( x , y ) 4.捲動視窗 window.scrollBy ( x , y ) |
|||||||||||||||||||||||||||||||||||||||
視窗在螢幕上的座標 |
window. screenLeft window.screenTop |
|||||||||||||||||||||||||||||||||||||||
視窗名 .name |
||||||||||||||||||||||||||||||||||||||||
window.navigate( 'http://www.yahoo.com.tw' ) |
||||||||||||||||||||||||||||||||||||||||
列印 |
window.print | |||||||||||||||||||||||||||||||||||||||
捲動 scroll |
|
|||||||||||||||||||||||||||||||||||||||
|
資訊方塊 --> sidebar (IE不適用)
配合內容調整視窗大小 -- > sizeToContent (IE不適用) |
|||||||||||||||||||||||||||||||||||||||
視窗的效果 |
|
|||||||||||||||||||||||||||||||||||||||
open |
傳回值的方式 window.returnValue = "傳回值" ;
直接控制母視窗的傳回物件 或是在母視窗傳入Argument然後在子視窗控制傳回值 winID = window.open('URL','WindowHeadName','features','replace') winID.location.href = newURL;
子視窗也可控制父視窗的方法
父視窗關閉子視窗
window.open(' ' , ' ' ,
'設定新視窗的特性'
)
|
|||||||||||||||||||||||||||||||||||||||
showModalDialog
在子視窗關閉前 |
ReturnValue = showModalDialog( url , sender , parameter )
直接使用參數傳入母視窗的物件來讓子視窗來直接改變或使用
在子視窗時使用
|
|||||||||||||||||||||||||||||||||||||||
showModelessDialog
子視窗開著時 |
||||||||||||||||||||||||||||||||||||||||
![]() |
||||||||||||||||||||||||||||||||||||||||
顯示各種特殊的對話方塊 |
|
|||||||||||||||||||||||||||||||||||||||
顯示色彩對話方塊 |
顯示色彩對話方塊 |
|||||||||||||||||||||||||||||||||||||||
顯示說明文件 | ||||||||||||||||||||||||||||||||||||||||
按下滑鼠右鍵執行別的視窗 |
|
|||||||||||||||||||||||||||||||||||||||
視窗內容的捲動 |
||||||||||||||||||||||||||||||||||||||||
window.frameElement |
.frameElement == null 時, 表示本頁不是在框架裡的頁面 .frameElement 可以取得引用的frame物件, ( <iframe iframe src="16_plug-in.html" id="frame1"></iframe > ) 如果我是16_plug-in.html 裡使用window.frameElement 即表示我取到了 id="frame1" 的上面這個物件 |
|||||||||||||||||||||||||||||||||||||||
window.length | 表示 內嵌frame的數量 | |||||||||||||||||||||||||||||||||||||||
document.embeds | ||||||||||||||||||||||||||||||||||||||||
document.plugins |
frame 物件 | |||||
---|---|---|---|---|---|
![]() |
|||||
框架的分割大小 高 寬 |
cols 左右分割大小 rows 上下分割大小 height width |
||||
基準位置 |
parent: 上層框架 self : 自己這個框架 top : 最上層框架 呼叫某一層框架的函式 parent . someFunction ( ) |
||||
框架的狀態 |
<FRAME SRC="upside.html" NAME="UP" onreadystatechange ="alert(this.readyState)"> | ||||
更換右側頁框內容 | parent . rightFrame . location . href = url | ||||
|