浅记js中的浏览器对象(windows,navigator,screen,location...)

浏览器对象

window

属性 作用
innerWidth、innerHeight 获取窗口的内部宽度和高度
outerWidth、outerHeight 获取浏览器窗口的整个宽高

navigator

属性 作用
navigator.appName 浏览器名称;
navigator.appVersion 浏览器版本
navigator.language 浏览器设置的语言
navigator.platform 操作系统类型
navigator.userAgen 浏览器设定的User-Agent字符串

这个值可以被用户更改,所以javaScript读取的值不一定准确

screen

属性 作用
screen.width 屏幕宽度,以像素为单位
screen.height 屏幕高度,以像素为单位
screen.colorDepth 返回颜色位数,如8、16、24

location

location对象标识当前页面的URL信息

属性 作用
location.href 浏览器地址栏中的完整地址串
.location.pathname URL的路径部分,请求映射的地址
location.search 获取?的内容
location.host 获取主机地址
location.port 获取端口号
location.hash 返回锚点的值,如"#…"
location.assign() 加载新的页面
location.reload() 重载当前界面

document

表示当前页面.同时由于HTML在浏览器中以DOM形式表示为树形结构,document对象就是整个DOM树的根节点.

属性 作用
document.title 表示读取<title></title>的内容,同时也可以更改
document.getElementById() 根据元素ID获取一个DOM节点
document.getElementByTagName() 表示按Tag名称获得一组DOM节点
document.cookie 获取当前页面得Cookie
发布了30 篇原创文章 · 获赞 6 · 访问量 7972

猜你喜欢

转载自blog.csdn.net/weixin_42792088/article/details/105129382