加载中...

BOM(Browser Object Model)对象模型

window对象是全局对象,基本BOM的属性和方法都是window的

window属性和方法

属性

location 位置对象

页面跳转 location.href = 'http://www.baidu.com'

在location.href 上修改的url,就是检测到手机后跳转的网址

!(function () {
    const userAgent = navigator.userAgent
    // 验证是否为Android或iPhone
    const android = userAgent.match(/(Android);?[\s\/]+([\d.]+)?/)
    const iphone = userAgent.match(/(iPhone\sOS)\s([\d_]+)/)
    // 如果是Android或iPhone, 则跳转至移动站点
    if (android || iphone) {
        location.href = 'http://m.itcast.cn'
    }
})()

histroy 历史对象

控制浏览器前进后退功能


方法

  • 点击某按钮,回到顶部
 window.scrollTo(0,0)
posted @ 2023-04-04 18:35  1502god  阅读(15)  评论(0)    收藏  举报
-->