Yuming Ren Curious and Learning 平平无奇

BOM

2017-08-10
yuming

window object

BOM: Browser Object Model

BOM核心object

全局作用域

Window扮演者ECMAScript global对象角色

全局变量不能通过delete 删除,window对象定义的属性可以。

var age = 29;
window.color = "red";

delete window.age;// false


delete window.color; //return true


console.log(window.age); //29
console.log(window.color); // undefined or error not defined

var语句添加的属性中[[Configurable]]特征值为false,因此无法被删除。

另外,访问未声明的变量会出错,但是查询对象window不会。通过这个方式可以查询window中是否存在这个属性。


var newAge = age; // error: age is not defined 
var newAge = window.age; // fine, no error. but newAge will be undefined.

Window vs frames

每一个frame对应一个window object

topobject始终指向最外层的框架,也就是window。而对于一个frame中的code,window 对象指向的是frame的实例。

parent始终指向当前frame的上层。最外层为top self:当前window

window location

对话框

alert(); confirm(); prompt();

if(confirm("are u sure?")) {
    alert("I do!");
} else {
    alert("what a nice weather!");
}

Chrome会在多个对话框的时候显示一个避免再次显示

location

property of window object also a property of document object

window.location and document.location 引用同一个对象

reload(): 作用为重载当前显示页面

location.reload(); //reload, may from cache if not modified
location.reload(); // reload from server

位于 reload() call 之后的代码

ref


下一篇 Javascript Events

Comments

Content