zoukankan      html  css  js  c++  java
  • JS-BOM(二)-document及其他

    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;
  • 相关阅读:
    sql 批量更新
    利用反射获取静态类的静态属性值(已知属性名称的字符串表示)
    远程桌面无法复制粘贴
    jquery分页滑动插件(鼠标可控制上下滑动)
    linux 基本操作
    dotnet core+nginx+supervisor
    dotnet core 托管
    net core 依赖注入
    绑定资源
    拉条改变字体大小
  • 原文地址:https://www.cnblogs.com/-Archenemy-/p/12458900.html
Copyright © 2011-2022 走看看