浏览器对象模型( Browser Object Model)
var ua=navigator.userAgent //浏览器特性
var isChrome=ua.indexOf(‘Chrome’)
console.log(isChrome)
console.log(screen.width)
console.log(screen.height)
console.log(location.href) //整个URL
console.log(location.protocol) //协议 http: or https:
console.log(location.host) //域名
console.log(location.pathname) //域名后的路径
console.log(location.search) //查询字符串 参数
console.log(location.hash) //哈希 #号后的就是哈希
history.back() //后退
history.forward() //前进
练习题
练习题1、如何检测浏览器的类型
var ua=navigator.userAgent
var isChrome=ua.indexOf(‘Chrome’)
console.log(isChrome)
练习题2、拆解url的各部分
参考location
网友评论