JavaScript基础学习笔记(四)

JavaScript 的浏览器对象模型 (BOM  Browser Object Model)
1、获得浏览器窗口的尺寸
对于非Explorer
width=window.innerWidth
height=window.innerHeight
对于Explorer 8 7 6 5
width=document.documentElement.clientWidth
height=document.documentElement.clientHeight
或则是document.body.clientHeight 和 document.body.clientWidth


所以获得通用尺寸的方法:
var w=window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;


var h=window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;
2、获得屏幕的宽度和高度
widnow.screen.availWidth
window.screen.availHeight
3、网页的路径名
window.location对象
使用是可以不加前缀window
http://www.w3school.com.cn/js/js_window_location.asp
所以:location.hostname; web主机的域名 www.w3school.com.cn
     location.pathname; 返回当前页面的路径名和文件名  /js/js_window_location.asp
     location.port; 返回web主机的端口  80或者是443
     location.protocol; 返回所使用的web协议 http://
     location.href;返回当前页面url  http://www.w3school.com.cn/js/js_window_location.asp
方法: window.location.assign("url") 加载新的文档
4、页面的前进与后退
widnow.history 对象
方法:
history.back()   //返回上一个页面
history.forward()    //前进到下一个页面(如果有后退过的话)


5、获得访问者浏览器的信息
window.navigator 对象
类似的对象可以用来检测浏览器的类型 ;例如: if(widnow.opear){}可以用来判断访问者的浏览器是哪种类型


6、Javascript信息框 :警告框 确认框 提示框
6.1、警告框: alert("str");
6.2、确认框: confirm("str") 返回使用者选择的值 true/false
6.3、提示框: prompt("str","默认值"); 需要用户输入信息然后点击确认 返回输入的值,如果电机取消则返回null
  
7、Javascript记时
记时事件:一定时间间隔就执行的对应的事件
t=setTimeout("js语句或者是函数调用 functionname()",时间ms);   t返回返回句柄值,可以用来取消记时函数
例如:
function timedCount()
{
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("timedCount()",1000);
}
clearTimeout(t) 则会取消t对应的记时函数

猜你喜欢

转载自blog.csdn.net/xiongshiyuan/article/details/79451287
今日推荐