浏览器对象

window
window对象不单充当全局作用域,而且还表示浏览器窗口
window对象有innerWidth和innerHeigth属性,可以获取浏览器的内宽和内高;outerWidth和outerHeigth用于获取整个宽高;

navigator
navigator对象表示浏览器的信息,常用属性:
navigator.appName :浏览器名称
navigator.appVersion :浏览器的版本
navigator.language :浏览器设置的语言
navigator.platform :操作系统类型
navigator.userAgent :浏览器设定的User-Agent字符串(User Agent中文名为用户代理,是http协议中的一部分,属于头域的组成部分)
 
screen
screen表示屏幕的信息,常用的属性有:
screen.width :屏幕宽度,以像素为单位;
screen.heigth : 屏幕高度,以像素为单位;
screen.colorDepth : 返回颜色的位数
 
location
location表示当前页面中URL的信息,常用操作:
URL:http://www.example.com:8080/path/index.html?a=1&b=2#TOP
location.href ;//'http://www.example.com:8080/path/index.html?a=1&b=2#TOP'
location.protocol; // 'http'
location.host; // 'www.example.com'
location.port; // '8080'
location.pathname; // '/path/index.html'
location.search; // '?a=1&b=2'
location.hash; // 'TOP'
要加载一个新的页面可以使用location.assign(),重新加载当前页可以使用location.reload();
 
document
document对象表示当前页面,浏览器会将HTML生成DOM树,而document就是DOM树的根节点
对象属性:
document.title                 //设置文档标题等价于HTML的<title>标签
document.bgColor               //设置页面背景色
document.fgColor               //设置前景色(文本颜色)
document.linkColor             //未点击过的链接颜色
document.alinkColor            //激活链接(焦点在此链接上)的颜色
document.vlinkColor            //已点击过的链接颜色
document.URL                   //设置URL属性从而在同一窗口打开另一网页
document.fileCreatedDate       //文件建立日期,只读属性
document.fileModifiedDate      //文件修改日期,只读属性
document.fileSize              //文件大小,只读属性
document.cookie                //设置和读出cookie  
document.charset               //设置字符集 简体中文:gb2312
常用对象方法:
document.write()                      //动态向页面写入内容
document.createElement(Tag)           //创建一个html标签对象
document.getElementById(ID)           //获得指定ID值的对象
document.getElementsByName(Name)      //获得指定Name值的对象
 
*** cookie有安全隐患,所以要坚持使用httpOnly
***设置cookie:
***response.addHeader("Set-Cookie", "uid=112; Path=/; HttpOnly")
 
history
history对象保存了浏览器的历史纪录,但是由于现在大量使用Ajax和页面交互,所以并不推荐使用它对页面进行前进和后退操作;
 
posted @ 2019-11-06 20:54  淡薄幽清  阅读(28)  评论(0)    收藏  举报