浏览器对象模型—BOM
-
window
-
alert()
window.alert("文本信息")
-
confirm
window.confirm("确认框"),点击"确定"返回值为true,点击"取消"返回值为false
-
prompt()
window.prompt("输入框信息",输入框的值——可选参数),返回输入框填写的值
-
setTimeout()
延时性的操作
window.setTimeout(function(){
console.log("xxxxx");
},1000)
-
setInterval()
定时器
var num = 0
var time = null
time = setInterval(function(){
num++;
if(num>10){
clearInterval(time);//清除定时器
}
console.log('num:'+num)
},1000)//每一秒执行一次
-
-
location
-
href 获取完整url
跳转页面
-
replace(newURL) 用一个新文档取代当前文档。
跳转页面
-
host 主机名+端口号
-
hostname 主机名
-
pathname 路径名称
-
hash 一个可读可写的字符串,该字符串是URL的锚部分(从#号开始的部分).
-
port 只获取端口号
-
search 获取查询内容字符串
-
protocol 协议
-
reload() 重新加载网页
-
-
Navigator 包含有关浏览器的信息
Navigator 对象属性
属性 说明 appCodeName 返回浏览器的代码名 appName 返回浏览器的名称 appVersion 返回浏览器的平台和版本信息 cookieEnabled 返回指明浏览器中是否启用 cookie 的布尔值 platform 返回运行浏览器的操作系统平台 userAgent 返回由客户机发送服务器的user-agent 头部的值 检测浏览器是否存在某插件
<script> console.log(navigator.plugins); function hasPlugin(name) { name = name.toLowerCase();//toLocaleLowerCase() 方法用于把字符串转换为小写。 for (var i = 0; i < navigator.plugins.length; i++) { if (navigator.plugins[i].name.toLocaleLowerCase().indexOf(name) > -1) { return true } else { return false } } } alert(hasPlugin("Flash")) //false alert(hasPlugin("Chrome PDF Plugin")) //true </script>
-
screen 包含有关客户端显示屏幕的信息。
Screen 对象属性
属性 说明 availHeight 返回屏幕的高度(不包括Windows任务栏) availWidth 返回屏幕的宽度(不包括Windows任务栏) colorDepth 返回目标设备或缓冲器上的调色板的比特深度 height 返回屏幕的总高度 pixelDepth 返回屏幕的颜色分辨率(每象素的位数) width 返回屏幕的总宽度 -
history
-
go()
go(0) 刷新
go(1)前进一次
go(-1)后退一次
-