JavaScript高级程序设计(第三版)学习笔记8章

BOM(Browser Object Model)-浏览器对象模型

1. window 对象

window 对象扮演着 ECMAScriptGlobal对象的角色,因此全局声明的对象或者方法会变成 window对象的属性和方法

  1. 窗口的可视区域大小
    在这里插入图片描述
  2. 打开新窗口
	window.open("http://www.baidu.com")
  1. 定时器
	// 超时调用    
    var timeoutId = setTimeout(function(){
        console.log("定时器");
    }, 1000)
    clearTimeout(timeoutId);    // 提前取消定时器

	// 间歇调用
	var num = 0;
    var interval = setInterval(function(){
        num++;
        console.log("间歇调用");
        if (num === 5){
            clearInterval(interval);
            console.log("Done");
        }
    }, 500)
  1. 弹出窗口
    alert("alert")
    confirm("are you sure");   // true | false
    prompt("input name:", "mak"); // 返回输入的值, 第二个参数为默认值

2. location 对象

  1. 属性
    1.
  2. 解析查询参数字符串
    function getQueryStringArgs() {
        // 取得要查询的字符串并去掉开头的问号
        var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
            args = {},
            items = qs.length ? qs.split("&"): [],
            item = null,
            name = null,
            value = null,
            //  在for 循环中使用
            i = 0,
            len = items.length;

        // 逐个将每一项目添加到args对象中
        for (i; i < len; i++) {
            item = items[i].split("=");
            name = decodeURIComponent(item[0]);
           value = decodeURIComponent(items[1]);
            if (name.length) {
                args[name] = value
            }
        }
        console.log(args);
        return args;
    }
  1. 方法
	// 下面两条语句效果相同
	window.location.assign("http://www.baidu.com")
	location.href = "http://www.baidu.com"
	// 跳转页面,但是不会保存历史记录(不能点击回退按钮)
	location.replace("http://www.baidu.com")
	// 重载页面
	location.reload()	// 优先缓存中加载
	location.reload(true)	// 从服务器重新获取

3. navigator 对象

该对象包含有关浏览器的信息,具体方法见 w3school

4. Screen 对象

该对象包含有关客户端显示屏幕的信息,具体方法见 w3school

5. history 对象

// 后退
	history.back()
	history.go(-1)
	// 前进
	history.forward()
	history.go(1)
	// 前进2页
	history.go(2)
	// 跳转到最近的百度界面
	history.go("www.baidu.com")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值