题目:
- 如何检测浏览器的类型
- 拆解url的各部分
知识点
- navigator
- screen
- location
- history
解答:
//navigator
var ua = navigator.userAgent //字符串
var isChrome = ua.indexOf('Chrome')
console.log(isChrome)
//screen
console.log(screen.width)
console.log(screen.height)
//location
console.log(location.href) //以下所有
console.log(location.protocol) //'http:' 'https:'协议
console.log(locaiton.host) //'blog.csdn.net'域
console.log(locaiton.pathname) //'classindex.html'路径
console.log(location.search) //'?t=1'参数
console.log(location.hash) //'#mid=100'哈希
//history
history.back()
history.forward()
//改变页面地址
location.href = 'http://imooc.com'