1.onload
window.onload = function () {
document.write("the page is loaded");
windo
}
2.setInterval
<!DOCTYPE html>
<html lang="ch">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript">
window.onload = function () {
var myinterval = setInterval(writeme, 1000);
var mystop = document.getElementById("stop");
mystop.onclick = function () {
clearInterval(myinterval);
}
}
function writeme() {
var show = document.getElementById("div");
show.innerHTML += Date("yy-m-d H:i:s") + "<br/>";
}
</script>
</head>
<body>
<div id="div"></div>
<input type="button" value="stop" id="stop" />
</body>
</html>
j结果:
3.history等
<script type="text/javascript">
window.onload = function () {
var mydiv;
var refresh = document.getElementById("refresh");
refresh.onclick = function () {
mydiv = document.getElementById("div");
mydiv.innerHTML += Date("yy-m-d H:i:s");
history.go(0);
//history.go(-3);
//history.go(3);
}
}
</script>
4.location等
location.href
window.onload = function () {
location.href="http://www.sina.com.cn";
}
location.reload
<script type="text/javascript">
window.onload = function () {
var refresh = document.getElementById("refresh");
var show = document.getElementById("show");
show.innerHTML = Date("yy-m-d H:i:s")
refresh.onclick = function () {
location.reload(true);//师父重新载入
}
}
</script>
setTimOut一定时间后执行函数
<script type="text/javascript">
window.onload = function () {
var refresh = document.getElementById("refresh");
var show = document.getElementById("show");
show.innerHTML = Date("yy-m-d H:i:s")
refresh.onclick = function () {
setTimeout(function () { location.href = "http://www.sohu.com" }, 5000);
}
}
</script>
5.screen等
<script type="text/javascript">
document.write(screen.availHeight + "px <br>");
document.write(screen.availWidth + "px <br>");
document.write(screen.width + "px <br>");
document.write(screen.height + "px <br>");
</script>
结果:
1040px
1920px
1920px
1080px