JavaScriptAPI中BOM:浏览器对象模型

BOM

BOM:browser object model (浏览器对象模型)

网址的组成

协议 + 主机 + 端口号 +路径 + 参数

协议 :http / https
主机 :域名 ip( ip 分为 公网ip局域网ip )
参数:?之后的内容
例如https://www.baidu.com/s?ie=UTF-8&wd=%E5%93%88%E5%93%88
加粗部分为参数

属性

console
location
history
navigator

console

Console 对象常见的两个用途:
1、显示网页代码运行时的错误信息。
2、提供了一个命令行接口,用来与网页代码互动。

location

1、location.hash:地址栏上#及后面的内容
2、location.host:主机名及端口号
3、location.reload():页面刷新

history

1、history.back:页面的后退
2、history.forward:页面的前进

<button id="btn">跳转页面</button>
<button id="forWord">前进</button>
<script>
    document.getElementById('btn').onclick = function () {
        window.location.href = './5-BOM.html'
    }
    // 前进
    document.getElementById('forWord').onclick = function () {
        window.history.forward()
    }
</script>

navigator

navigator 浏览器嗅探

<body>
    <button id="btn">跳转</button>
    <button id="reload">重新加载</button>
    <button id="back">返回</button>
</body>
<script>
    // console.log(age);
    // console.log(window);
    // console.log(name);
    /*
          BOM:
             属性:console location history navigator
             方法:alert()  prompt() confirm()
             事件:onload() onscroll()
    */
    //alert('我是弹框')
    //var str = prompt('我是带有输入框的弹框')
    // var flag = confirm('请充值')
    // console.log(flag);
    // if (flag) {
    //     console.log('VIP玩家,你好');
    // } else {
    //     console.log('没钱别玩游戏');
    // }
    /*
       location
      */
    console.log(location);
    console.log(window.location);
    //  hash:地址栏上#及后面的内容
    console.log(window.location.hash);
    // host:主机名及端口号
    console.log(window.location.host);
    document.getElementById('btn').onclick = function () {
        window.location.href = 'http://www.taobao.com'
    }
    //页面刷新
    document.getElementById('reload').onclick = function () {
        location.reload()
    }
    /*
        history
      */
    console.log(window.history);
    // 后退
    document.getElementById('back').onclick = function () {
        window.history.back()
    }
    /*
    navigator  浏览器嗅探
    */
    console.log(window.navigator);
</script>

方法

alert() 弹框
prompt() 带输入框的弹框
confirm() 带确认取消按钮的弹框

alert('我是弹框')

alert()           弹框

var str = prompt('我是带有输入框的弹框')

prompt()       带输入框的弹框
confirm()      带确认取消按钮的弹框

事件

onload()加载完成事件
onscroll()滚动事件
滚动条事件

 var num = 1
    onscroll = function () {
        num++
        console.log(num);
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值