JavaScript | BOM对象(BrowserObjectModel)(内含常用对象方法)

一、window对象

1.属性

下面两个现在也慢慢被淘汰了,不经常用了

frames  //窗口数组

top  //顶级窗口

<html>
<head>
    <meta charset="UTF-8" />
    <title>index</title>
</head>
<frameset rows="50,*">
    <frame src="top.html">
        <frameset cols="150,*">
            <frame src="left.html" noresize> //边界线不可拖动
            <frame src="right.html">
        </frameset>
</frameset>
</html>

2.方法

alert();
confirm();
prompt();
setInterval();
clearInterval();
setTimeout();
clearTimeout();

二、navigator浏览器特性

1. 属性

userAgent  //更精确的版本

<script>
    nav=navigator.userAgent;
    ntype=nav.match(/chrome|firefox|trident/i);//分别为谷歌,火狐,IE浏览器
    alert(ntype);
</script>
//根据上面代码可以判断当前的浏览器

三、screen屏幕对象

1.属性

availHeight //屏幕有效高
availWidth //屏幕有效宽
height //屏幕高
width //屏幕宽
<html>
<head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <style>
        *{
            font-family: 微软雅黑;
        }
    </style>
</head>
<body>
    <h1>aaaaaaaaaaaaaaaaaaaa</h1>
</body>
<script>
    sw=screen.width;
    sh=screen.height;
    saw=screen.availWidth;
    sah=screen.availHeight;
    document.write(sw+'-'+sh+'-'+saw+'-'+sah);
</script>
</html>

四、history对象

1. 方法:

back()  //后退一个历史

forward()  //前进一个历史

go(-1)  //前进一个历史

test0810.html
<html>
<head>
    <meta charset="UTF-8" />
    <title>Document</title>
</head>
<body>
    <div >
        <a href="left.html">下一页</a>
    </div>
</body>
</html>

left.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
</head>
<body>
    <div>
        <a href="javascript:" id="aid">返回上一页</a>
    </div>
</body>
<script>
    aobj=document.getElementById('aid');
    aobj.onclick=function(){
        history.back();
    }
</script>
</html>

五、location地址栏

1.属性

hash  //获取url里的锚点#abc

<script>
    alert(location.hash);
</script>

host  //域名

<html>
<head>
    <meta charset="UTF-8" />
    <title>Document</title>
</head>
<body>
    <h1>aaaaaaaaaaaaaaa</h1>
    <h1>aaaaaaaaaaaaaaa</h1>
    <h1>aaaaaaaaaaaaaaa</h1>
</body>
<script>
    alert(location.host);
</script>
</html>

href  //当前的url地址

<script>
    document.write(location);
    document.write("<br>");
    document.write(location.href);
</script>
//说明二者等价

pathname  //index.html 页面的名称

<script>
    alert(location.pathname);
</script>

protocol  //协议 

<script>
    document.write(location.protocol);
</script>

search  //参数 ?id=10&name=user1

<script>
    alert(location.search);
</script>

2. 方法

reload(); 

<body>
    <div class="main">
        <script>
            dobj=new Date;
            h=dobj.getHours();
            m=dobj.getMinutes();
            s=dobj.getSeconds();
            document.write(h+'-'+m+'-'+s);
        </script>
    </div>
    <p><a href="javascript:" id="aid">刷新</a></p>
</body>
<script>
    aobj=document.getElementById('aid');
    aobj.onclick=function(){
        location.reload();
    }
</script>
//刷新当前页面也可以重新获取当前时间

六、document对象

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值