//获得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(); //不推荐使用,容易覆盖页面文档
//获得历史记录对象 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 :包含有关浏览器的信息。 //获得导航对象 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 对象包含有关客户端显示屏幕的信息。 //获得屏幕对象 let screenobj = window.screen; //得到整个屏幕的高度和宽度(包括任务栏--电脑屏幕最下方的一块) let scrrenW = screenobj.width; let screenH = screenobj.height; //得到屏幕的高度和宽度(去除了任务栏的) let sw = screenobj.availWidth; let sh = screenobj.availHeight;
原文:https://www.cnblogs.com/-Archenemy-/p/12458900.html