JavaScript 计时器,History 对象(window),Location对象(window),Navigator对象

1,计时器setInterval()  在执行时,从载入页面后每隔指定的时间执行代码。 

setInterval(代码,交互时间);


2,计时器setTimeout(),在载入后延迟指定时间后,去执行一次表达式,仅执行一次。
递归,就是在运行的过程中调用自己。
setTimeout()计时器,在载入后延迟指定时间后,去执行一次表达式,仅执行一次。
setTimeout(代码,延迟时间);

function startCount() {
document.getElementById('count').value=num;
num=num+1;
setTimeout("startCount()",1000);
}

3,setTimeout()和clearTimeout()一起使用,停止计时器。

clearTimeout(id_of_setTimeout)

<script type="text/javascript">
var num=0;
var i;
var j;
function startCount(){
document.getElementById('count').value=num;
num=num+1;
i=setTimeout("startCount()",1000);
}
function stopCount(){
j =clearTimeout(i);
}
</script>
</head>
<body>
<form>
<input type="text" id="count" />
<input type="button" value="Start" onclick= "startCount()"/>
<input type="button" value="Stop" onclick="stopCount()" />

History 对象

history对象记录了用户曾经浏览过的页面(URL),并可以实现浏览器前进与后退相似导航的功能。

window.history.[属性|方法]

window.history.go(1)是返回历史记录上一个页面
window.history.go(-1)是返回历史记录下一个页面
window.history.back()
是返回历史记录上一个页面
window.history.forward()是返回历史记录下一个页面

Location对象

location用于获取或设置窗体的URL,并且可以用于解析URL。

location.[属性|方法]



Navigator对象

Navigator 对象包含有关浏览器的信息,通常用于检测浏览器与操作系统的版本


 document.write(navigator.appVersion);

userAgent

返回用户代理头的字符串表示(就是包括浏览器版本信息等的字符串)     navigator.userAgent

screen对象

screen对象用于获取用户的屏幕信息。window.screen.属性

屏幕分辨率的高和宽

window.screen 对象包含有关用户屏幕的信息。
1. screen.height 返回屏幕分辨率的高
2. screen.width 返回屏幕分辨率的宽
注意:
1.单位以像素计。
2. window.screen 对象在编写时可以不使用 window 这个前缀。
我们来获取屏幕的高和宽,代码如下:

<script type="text/javascript">
  document.write( "屏幕宽度:"+screen.width+"px<br />" );
  document.write( "屏幕高度:"+screen.height+"px<br />" );
</script>

屏幕可用高和宽度

1. screen.availWidth 属性返回访问者屏幕的宽度,以像素计,减去界面特性,比如任务栏。

2. screen.availHeight 属性返回访问者屏幕的高度,以像素计,减去界面特性,比如任务栏。

注意:

不同系统的任务栏默认高度不一样,及任务栏的位置可在屏幕上下左右任何位置,所以有可能可用宽度和高度不一样。

我们来获取屏幕的可用高和宽度,代码如下

<script type="text/javascript">
document.write("可用宽度:" + screen.availWidth);
document.write("可用高度:" + screen.availHeight);
</script>
原文地址:https://www.cnblogs.com/liaolijun/p/7279947.html