window is an instance of the browser, the browser, the window has a double role, it is both an interface accessible by javascript browser window, and a global object the ECMAScript predetermined
window global variables window.num = 1 = var num = 1
window object:
window.alert("")
window.prompt(''提示文字")
window.confirm("提示文字") //确定 返回true 取消返回false
window.open() //打开一个新窗口
window.close() //关闭当前窗口
window.setTimeout() //定时器 超时调用
window.setInterval() //定时器 间歇调用
var time1=setTimeout(function(){
console.log(1)
},2000)
clearTimeout(time1)
var timer=null
timer=setInterval(function(){
console.log(0)
clearInterval(timer)
},1000)
The location object
location.href //返回当前完整url
location.hash //返回url #后面的内容包括#
location.pathname //返回url中的目录或文件名
location.host //返回服务器名称或端口号
location.search //返回url查询字符串 ?后面的内容包括?
location.hostname //返回不带端口号的服务器名称
location.port //返回url指定的端口号
location.protocol //返回页面使用的协议
location.hash="#top"
location.href="index.html" //跳转到index.html页面,并且生成历史记录
window.location="index.html" //location.href== window.location
location.replace("index.html")//重定向url 不会产生历史记录
history objects
history.back() //返回到历史纪录的上一步
history.go(-1) //和上面一样 -2返回历史记录前两部
history.forward() //返回历史记录的下一步
history.go(1) //和上面一样
screen objects
screen.availWidth //获取屏幕宽度
screen.availHeight //获取屏幕高度
window.innerWidth //获取窗口的宽度
window.innerHeight //获取窗口的高度
Navigator Object
determines the type of browser
the terminal apparatus determines a mobile or PC
//封装一个检测浏览器类型的函数
navigator.userAgent //用来识别浏览器名称版本操作系统等内容
function getBrowser(){
var export=navigator.userAgent.toLowerCase(),browser;
if(export.indexOf("msie")>-1){
browser="IE"
}else if(export.indexOf("chrome")>-1){
browser="chrome"
}else if(export.indexOf("opera")>-1){
browser="opera"
}else if(export.indexOf("safari")>-1){
browser="safari"
}
return browser
}