BOM对象得详细解析

1、BOM核心对象是window

标识一个浏览器的实例,也是js访问浏览器窗口的一个接口!
有事ES规定的一个Global对象。
全局变量不能通过deleted删除。
直接在window上定义属性可以删除。

 var age = 18;
    window.color = "red";
    //在IE < 9 时抛出错误,其他浏览器返回false
    deleted window.age;
    //在IE < 9 时抛出错误,其他浏览器返回true
    deleted window.color;

    alert(window.age);//18
    alert(window.color);//undefined
    var添加属性时,[[Configurable]]属性设置为false,所以deleted不能删除;
    尝试访问未声明的变量,会抛出错误。通过window则不会;
    //这里抛出错误。因为oldValue未定义;
    var newValue = oldValue;
    //这里不会抛出错误,因为是一次属性查询
    var newValue = window.oldValue;

2、frames集合中保存着每个window

从左至右 从上至下顺序
每个window都有个name属性
获取窗口左边和上边位置的兼容写法:
var leftPos = (typeof window.screenLeft == “number”)?
window.screenLeft : window.screenX;
var topPos = (typeof window.wcreenTop == “number”)?
window.screenTop : window.screenY;
IE Opera Chrome是screenLeft和screenTop
Firefox是screenX和screenY

3、window.open()打开一个新的窗口

接受四个参数:open(url,windowTarger,string,Boolean)
a、要加载的url
b、窗口目标
c、一个特性字符串
d、表示是否替代当前窗口的Boolean值
window.open(url,topTrame)
等同于:

4、window.location = document.location;

5、location.search返回从问号到结尾的内容。

获取参数函数:
function getQueryStringArgs(){
//取得岔村字符串并去掉开头的问号
var qs = (location.search.length > 0 ? location.search.substring(1) : “”),
//保存数据的对象
args = {},
//取得每一项
items = qs.length ? qs.split("&") : [],
item = null,
name = null,
value = bull,
//在for循环中使用
i= 0,
len = items.length;
//逐个将每一项添加到args对象中
for(i=0;i<len;i++){
item = items[i].split("=");
name = decodeURIComponent(item[0]);
value = decodeURIComponent(item[1]);
if(name.length){
args[name] = value;
}
}
return args;
}

6、location.assign(url);

 window.location = url;
    location.href = url;
    都是通过隐式调用assign实现跳转的。
    修改location的方式:-------------------------
    location.hash
    location.hostname
    location.pathname
    location.port
    location.search
    除了hash外都会重新加载!
    以上都会生成新纪录,可以返回。
    可以用location.replace(url)方法实现不生成可后退新链接。

7、navigator对象

 每个浏览器都有自己的navigator对象
    navigator.plugins数组可以检测浏览器安装的插件,IE除外!

8、screen对象:表示浏览器窗口外部的显示器信息

9、history对象:上网的历史纪录;

欢迎star本人github:https://github.com/flyku

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值