6.3BOM中其他常见对象

location对象

location对象,是window对象的一个属性,代表浏览器上URL地址栏,使用location对象可以操作地址栏

<!DOCTYPE html>
<html>
        <head>
                <meta charset="UTF-8">
                <title></title>
                <script>
                        function fun1(){
                                console.log(location.host);// 服务器的IP+端口号
                                console.log(location.hostname);// IP 
                                console.log(location.port);// 端口号
                                console.log(location.href);// 地址栏中具体的文字
                        
                                location.href="https://www.baidu.com"
                        }
                        
                </script>
        </head>
        <body>
                <input type="button" value="测试location" onclick="fun1()" />
        </body>
</html>

history对象

history对象是window对象的一个属性,代表浏览器访问历史记录,通过history的操作我们可以实现翻阅浏览器历史网页

<!DOCTYPE html>
<html>
        <head>
                <meta charset="UTF-8">
                <title></title>
                <script>
                        function fun1(){
                                window.history.forward();
                                
                        }
                        function fun2(){
                                history.back();
                        }
                        function fun3(){
                                history.go(2); // 正整数 向前跳转 * 页  负整数 向后跳转*页
                        }
        
                        
                </script>
        </head>
        <body>
                <a href="a.html" target="_self">pageA</a>
                <input type="button" value="向前" onclick="fun1()"/>
                <input type="button" value="向后" onclick="fun2()"/>
                <input type="button" value="go" onclick="fun3()"/>
        </body>
</html>

screen和navigator

screen代表屏幕,navigator代表浏览器软件本身,通过这两个对象可以获得屏幕和浏览器软件的一些信息

<!DOCTYPE html>
<html>
        <head>
                <meta charset="UTF-8">
                <title></title>
                <script>
                        function fun1(){
                                console.info(window.screen.width)
                                console.info(window.screen.height)
                                console.info(navigator.userAgent)
                                console.info(navigator.appName)
                        }
                </script>
        </head>
        <body onload="fun1()">
        </body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值