JavaScript 浏览器对象
2016-04-21 20:16
901 查看
window对象是BOM的核心,window对象指当前的浏览器窗口。
1.打开窗口
window.open 弹出新窗口的命令;
page.html 弹出窗口的文件名;
newwindow 弹出窗口的名字(不是文件名),非必须,可用空”代替;
height=100 窗口高度;
width=400 窗口宽度;
top=0 窗口距离屏幕上方的象素值;
left=0 窗口距离屏幕左侧的象素值;
toolbar=no 是否显示工具栏,yes为显示;
menubar,scrollbars 表示菜单栏和滚动栏。
resizable=no 是否允许改变窗口大小,yes为允许;
location=no 是否显示地址栏,yes为允许;
status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;
2.计时器
setInterval(代码,交互时间);
取消计时器clearInterval()
setTimeout(代码,延迟时间);
setTimeout()和clearTimeout()一起使用,停止计时器。
3.history对象
history对象记录了用户曾经浏览过的页面(URL),并可以实现浏览器前进与后退相似导航的功能。
注意:从窗口被打开的那一刻开始记录,每个浏览器窗口、每个标签页乃至每个框架,都有自己的history对象与特定的window对象关联。
4.Location对象
l
4000
ocation用于获取或设置窗体的URL,并且可以用于解析URL。
5.Navigator对象
Navigator 对象包含有关浏览器的信息,通常用于检测浏览器与操作系统的版本。
6.userAgent
返回用户代理头的字符串表示(就是包括浏览器版本信息等的字符串)
7.screen对象
screen对象用于获取用户的屏幕信息。
1.打开窗口
window.open(('page.html', 'newwindow', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no');//打开新窗口
window.open 弹出新窗口的命令;
page.html 弹出窗口的文件名;
newwindow 弹出窗口的名字(不是文件名),非必须,可用空”代替;
height=100 窗口高度;
width=400 窗口宽度;
top=0 窗口距离屏幕上方的象素值;
left=0 窗口距离屏幕左侧的象素值;
toolbar=no 是否显示工具栏,yes为显示;
menubar,scrollbars 表示菜单栏和滚动栏。
resizable=no 是否允许改变窗口大小,yes为允许;
location=no 是否显示地址栏,yes为允许;
status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;
2.计时器
setInterval(代码,交互时间);
<script type="text/javascript"> var int = setInterval(clock, 2000) function clock() { var time = new Date(); document.getElementById("clock").value = time; } </script> <input type="text" id="clock" size="50" />
取消计时器clearInterval()
<script type="text/javascript"> function clock() { var time=new Date(); document.getElementById("clock").value = time; } var i=setInterval("clock()",1000); </script> <input type="text" id="clock" size="50" /> <input type="button" value="Stop" onclick="clearInterval(i)" />
setTimeout(代码,延迟时间);
<script type="text/javascript"> setTimeout("alert('Hello!')", 3000 ); </script>
setTimeout()和clearTimeout()一起使用,停止计时器。
<script type="text/javascript"> var num = 0; var i; function startCount() { document.getElementById('count').value = num; num = num + 1; i = setTimeout("startCount()", 1000); } function stopCount() { clearTimeout(i); } </script> <input type="button" value="Start" id="count" onClick="startCount()"/> <input type="button" value="Stop" onClick="stopCount()"/>
3.history对象
history对象记录了用户曾经浏览过的页面(URL),并可以实现浏览器前进与后退相似导航的功能。
注意:从窗口被打开的那一刻开始记录,每个浏览器窗口、每个标签页乃至每个框架,都有自己的history对象与特定的window对象关联。
<script type="text/javascript"> var HL = window.history.length ; document.write(HL); function last(){ var last = window.history.back(); } function next(){ var next = window.history.forward(); } function go(){ var go = window.history.go("number");//number为浏览器前历史记录数值如返回上一页则为go(1); } </script>
4.Location对象
l
4000
ocation用于获取或设置窗体的URL,并且可以用于解析URL。
alert(window.location.href)
5.Navigator对象
Navigator 对象包含有关浏览器的信息,通常用于检测浏览器与操作系统的版本。
var browser=navigator.appName; var b_version=navigator.appVersion; document.write(browser); document.write("<br>"); document.write(b_version);
6.userAgent
返回用户代理头的字符串表示(就是包括浏览器版本信息等的字符串)
var u_agent = navigator.userAgent; var B_name="Failed to identify the browser"; if(u_agent.indexOf("Firefox")>-1){ B_name="Firefox"; }else if(u_agent.indexOf("Chrome")>-1){ B_name="Chrome"; }else if(u_agent.indexOf("MSIE")>-1&&u_agent.indexOf("Trident")>-1){ B_name="IE(8-10)"; } document.write("B_name:"+B_name+"<br>"); document.write("u_agent:"+u_agent+"<br>");
7.screen对象
screen对象用于获取用户的屏幕信息。
alert( window.screen.属性)
相关文章推荐
- JQuery1——基础($对象,选择器,对象转换)
- Android Manifest 用法
- Android学习笔记(二九):嵌入浏览器
- Android java 与 javascript互访(相互调用)的方法例子
- Python动态类型的学习---引用的理解
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- JavaScript演示排序算法
- javascript实现10进制转为N进制数
- Linux下XWindow图形界面的基本概念
- 回顾 Firefox 历史
- 小白观察:微软释放出其基于 Chromium 的 Edge 浏览器
- 最后一次说说闭包
- Ajax
- 2019年开发人员应该学习的8个JavaScript框架
- HTML中的script标签研究
- 对一个分号引发的错误研究
- 异步流程控制:7 行代码学会 co 模块