2018.10.03 学习笔记 // 前端Javascript // BOM与DOM

题目:

  • 如何检测浏览器的类型
  • 拆解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'

猜你喜欢

转载自blog.csdn.net/weixin_41004238/article/details/82932175