BOM (浏览器对象模型),js与浏览器对话
1、window对象,表示浏览器窗口;全局变量是window对象的属性,全局方法是window对象的方法。
2、window.screen 表示用户屏幕信息
screen.availWidth, screen.availHeight 可用的屏幕宽度、高度
3、window.location 对象用于获得当前页面的地址 (URL),并把浏览器重定向到新的页面。
location.href 返回当前页面的url;location.hostname 返回web主机的域名;location.assign( " http://www.baidu.com "); 加载一个新的文档
4、history.back(); history.forward(); // 浏览器后退,前进
5、Navigator对象获得浏览器信息
6、js计时器, var x = setTimeout( " js语句 " , 毫秒 ); clearTimeout(); 取消setTimeout()
7、cookie:创建、存储cookie
function setCookie(c_name,value,expiredays) { var exdate=new Date() exdate.setDate(exdate.getDate() + expiredays) document.cookie=c_name + "=" + escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) }
function getCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "=") if (c_start!=-1) { c_start=c_start + c_name.length+1 c_end=document.cookie.indexOf(";",c_start) if (c_end==-1) c_end=document.cookie.length return unescape(document.cookie.substring(c_start,c_end)) } } return "" }