首页 > Web开发 > 详细

JS-BOM(二)-document及其他

时间:2020-03-10 21:57:31      阅读:52      评论:0      收藏:0      [点我收藏+]

document/文档对象 

//获得document对象
    let docObj = window.document
    let docObj = document;
    //window可以省略

//获得滚动条的的高度
    let sh =   document.documentElement.scrollTop;

    //窗体的滚动事件
    window.onscroll=()=>{
        let sh =   document.documentElement.scrollTop;
    }
    //常与窗体滚动事件联用
    
//返回当前文档的域名
    document.domain

//返回文档被最后修改的日期和时间
    document.lastModified

//referrer:返回是是页面从哪个服务器过来的,浏览历史中的前一个URL-可以做防盗链
    let url_val = document.referrer;

//返回当前文档的标题
    console.log(document.title);
    document.title="修改的标题";

    document.getElementsByTagName("title")[0].innerHTML="修改的标题";
    //通过查询节点的方式修改标题

//返回当前文档的 URL
    document.URL
    //window.location.href  也可以通过查询定位对象获得
//向文档写 HTML 表达式 或 JavaScript 代码
    document.write();  
    //不推荐使用,容易覆盖页面文档

histroy/历史对象

//获得历史记录对象
    let histroyobj = window.history;
    
    let length_val = histroyobj.length;
    //属性  length

//向后
    histroyobj.back();
    histroyobj.go(-1);

//向前
    histroyobj.forward();
    histroyobj.go(1)
         
//刷新
    window.location.reload();
    histroyobj.go(0);

Navigator/导航对象

//Navigator :包含有关浏览器的信息。

    //获得导航对象
    window.navigator

    //获得浏览器的名称
    window.navigator.appName

    //获得浏览器的信息
    window.navigator.userAgent

//用navigator判定浏览器
    var strContent = window.navigator.userAgent;
    if(strContent.indexOf("MSIE")!=-1){
        alert("你使用的时ie浏览器");
    }else if(strContent.indexOf("Firefox")!=-1){
        alert("你使用的是火狐览器");
    }else if(strContent.indexOf("Chrome")!=-1){
        alert("你使用的是谷歌览器");
    }

//对于浏览器的判定多用于兼容
    //对于浏览器的兼容大多由于IE引起,所以我们只需要判定IE浏览器即可
    if(document.all){
        alert("不支持ie浏览器,请更换");
    }

Screen/屏幕对象

//Screen 对象包含有关客户端显示屏幕的信息。

    //获得屏幕对象
    let screenobj = window.screen;

    //得到整个屏幕的高度和宽度(包括任务栏--电脑屏幕最下方的一块) 
    let scrrenW = screenobj.width;
    let screenH = screenobj.height;

    //得到屏幕的高度和宽度(去除了任务栏的) 
    let  sw = screenobj.availWidth;
    let  sh = screenobj.availHeight;

JS-BOM(二)-document及其他

原文:https://www.cnblogs.com/-Archenemy-/p/12458900.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!