window对象(全局对象)
window对象是全局对象,所有在浏览器可以直接使用的方法,都是window对象的方法
1、计时器方法
// window.setTimeout(() => {
// console.log('hello world')
// }, 1000)
// function fun () {
// console.log(this)
// }
// window.fun()
2、弹出框方法
// 弹出框一
// alert('hello world')
// 弹出框二
// let str = prompt('请输入你的名字')
// console.log(str);
// 弹出框三
// let result = confirm('确定是否删除此条记录')
// console.log(result);
screen对象包含有关用户屏幕的信息
location对象用于获得当前页面的地址(URL),并把浏览器重定向到新的页面
1、location.href ————-属性返回当前页面的URL,"https://www.baidu.com/"
2、location.hostname——主机的域名,"www.baidu.com"
3、location.pathname——当前页面的路径和文件名,"/s"
4、location.port————--端口,"8080"
5、location.protocol——---协议,"https:"
页面跳转 location.href = "http://baidu.com"
history对象包含浏览器的历史
navigator对象包含有关访问者浏览器的信息
练习:
1、使用prompt实现一个猜数字游戏
2、使用confirm实现一个水果列表删除的提示功能