JavaScript BOM操作

一、学习BOM的预备知识

html触发js的简单方法

<button onclick="f1()">点我</button>

function f1(){
			alert('已触发')
		}

二、什么是BOM操作

就是对浏览器对象(window)的操作

screen

		//screen.width/height 属性返回以像素计的访问者屏幕宽度/高度。
		//这个宽度/高度,是和浏览器的可视大小无关的
		console.log(screen.width)
		console.log(screen.height)
		
		//Window Screen availWidth/availHeight可用宽度/高度
		//这个宽度/高度,是和浏览器的可视大小无关的
		console.log(screen.availWidth)
		console.log(screen.availHeight)
		//screen.colorDepth返回色深
		console.log(screen.colorDepth)
		//screen.pixelDepth 属性返回屏幕的像素深度。
		console.log(screen.pixelDepth)

location

		//location
		//window.location.href返回页面地址
		console.log(location.href);
		//href可以进行跳转
		//location.href = "./page.html"
		//location.hostname用来获取页面 服务器 的域名或者地址
		console.log(window.location.hostname)
		//window.location.pathname 属性返回当前页面的路径名。
		console.log(location.pathname)
		//window.location.protocol 属性返回页面的 web 协议。
		console.log(location.protocol)

history

		//返回前一个浏览的页面
		history.back()
		//用来回到刚刚点击返回的页面
		history forward()
		//用来记录该页面访问过多少个网站,为1的时候,就是指访问过当前页
		console.log(history.length)

navigator

		//navigator
		//获取浏览器是否启用cookie
		console.log(navigator.cookieEnabled)
		//获得用户使用的浏览器的用户代理报头
		//大概是指,浏览器所使用的某种引擎
		console.log(navigator.userAgent )
		//platform获取操作系统
		console.log(navigator.platform)
		//language获取语言
		console.log(navigator.language)

弹窗

		//警示窗
		window.alert("我是一个警示窗");
		
		var temp = window.confirm("这是一个确认窗");
		console.log(temp);
		
		//提示框用来让用户输入值
		var person = prompt("请输入您的姓名");
		console.log(person)
		
		//   \n可以用来换行

时间触发器

		//延时执行
		<button onclick="myVar=setTimeout(f1,1000)">点我</button>
		<button onclick="clearTimeout(myVar)">点我取消</button>

		function f1(){
			alert("你好")
		}
		//循环执行
		var i = 0;
		var s1 = setInterval(function(){
			console.log("过了"+i+"秒")
			i++;
		},1000)
		//取消方法:
		function f2(){
			clearInterval(s1)
		}
		<button onclick="f2()">点我取消</button>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值