当前位置: 移动技术网 > IT编程>开发语言>JavaScript > JS-BOM操作

JS-BOM操作

2020年10月24日  | 移动技术网IT编程  | 我要评论
BOM,JS,前端

JS-BOM操作(一)

window

window.innerHeight:浏览器窗口内的高度,以像素计算
window.innerWidth:浏览器窗口的内宽度
document.body.clientHeight是body元素所带的高度
document.body.clientWidth是body元素所带的宽度

/*window.innerHeight == document.documentElement.clientHeight
  浏览器窗口的高度
* window.innerWidth == document.documentElement.clientWidth
* 浏览器窗口的宽度
* */
let InH = window.innerHeight;
let InW = window.innerWidth;
console.log("浏览器显示的高度"+InH);
console.log("浏览器显示的宽度"+InW);

let CH = document.documentElement.clientHeight;
let CW = document.documentElement.clientWidth;
console.log("浏览器显示的高度"+CH);
console.log("浏览器显示的宽度"+CW);
/*document.body.clientHeight是body元素所带的高度
* document.body.clientWidth是body元素所带的宽度
* */
let CH1 = document.body.clientHeight;
let CW1 = document.body.clientWidth;
console.log("body的高度"+CH1);
console.log("body的宽度"+CW1);

window.open();//打开新窗口
window.close();//关闭当前窗口
window.moveTo(20,50);//移动当前窗口
window.resizeTo()//重新调整当前窗口

window Screen

screen.width:访问者屏幕宽度;
screen.height:访问者屏幕高度

screen.availWidth;访问者屏幕的可用宽度
screen.availHeight;访问者屏幕的可用高度
screen.colorDepth;颜色的比特数
screen.pixelDepth;返回屏幕的像素深度

let YhW = screen.width;
let YhH = screen.height;
console.log("访问者屏幕宽度"+YhW);
console.log("访问者屏幕高度"+YhH);

let SW=screen.availWidth;
let SH=screen.availHeight;
let Sc=screen.colorDepth;
let Sp=screen.pixelDepth;

console.log("访问者屏幕的可用宽度"+SW);
console.log("访问者屏幕的可用高度"+SH);
console.log("颜色的比特数"+Sc);
console.log("返回屏幕的像素深度"+Sp);

window.Location

window.location.href:返回当前页面的href
window.location.hostname返回主机名
window.location.pathname返回当前页面的路径或文件名
window.location.protocol:返回当前Web协议
window.location.assign:加载新文档

/*Window Location*/
//返回当前页面的href
let href = window.location.href;
//返回主机名
let hs = window.location.hostname;
//返回当前页面的路径或文件名
let pathname = window.location.pathname;
//当前web协议
let protocol = window.location.protocol;
//加载新文档
let assign = window.location.assign;
console.log(href);
console.log(hs);
console.log(pathname);
console.log(protocol);
console.log(assign);

window.History

window.history加载历史列表的前一个URL
history.forward();相当于点前进按钮

/*Window History
* history = window.history
* */
//加载历史列表的前一个URL
history.back();
//相当于点前进按钮
history.forward();

window.navigator

//如果启用cookie则返回true
navigator.cookieEnabled;
//appName返回浏览器应用程序名称
navigator.appName;
//appCodeName返回浏览器应用程序代码名称
navigator.appCodeName;
//appVersion返回有关浏览器的版本信息
navigator.appVersion;
//userAgent返回由浏览器发送到服务器的用户代理报头
navigator.userAgent;
//language返回浏览器语言
navigator.language;
//onLine浏览器是否在线
navigator.onLine;
//platform返回浏览器平台
navigator.platform;
//javaEnabled()返回Java是否启用
navigator.javaEnabled();

本文地址:https://blog.csdn.net/batLk/article/details/109263246

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网