window.document.write("width"+window.innerWidth+"height"+window.innerHeight);
不包括框的宽度
打开网页:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button id="btn" οnclick="btnClicked()">button</button>
<script>
//window.document.write("width"+window.innerWidth+"height"+window.innerHeight);
function btnClicked(){
window.open("openhtml.html");
}
</script>
</body>
</html>
加参数:
window.open("openhtml.html","windowname","height=200,weight=200,top=100,left=100,toolbar=no,menubar=no");
关闭窗口:
window.close();
window对象很多对象的祖先~~
计时器:
开始与停止
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button id="btn" οnclick="stopTime()">button</button>
<p id="ptime"></p>
<script>
var mytime=setInterval(function(){
getTime();
},1000);
function getTime(){
var d=new Date();
var t= d.toLocaleTimeString();
document.getElementById("ptime").innerHTML=t;
}
function stopTime(){
clearInterval(mytime);
}
</script>
</body>
</html>
延迟执行:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button id="btn" οnclick="mywin()">button</button>
<p id="ptime"></p>
<script>
var min;
function mywin(){
win=setTimeout(function(){alert("hello");},3000);
}
</script>
</body>
</html>
一直执行:
var min;
function mywin(){
alert("hello");
win=setTimeout(function(){mywin()},3000);
}
暂停:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body οnlοad="myWin()">
<button id="btn" οnclick="stopWin()">button</button>
<p id="ptime"></p>
<script>
var min;
function myWin(){
alert("hello");
win=setTimeout(function(){myWin()},3000);
}
function stopWin(){
clearTimeout(win);
}
</script>
</body>
</html>
历史:
foward:/back:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button οnclick="goceshi()">button</button>
<script>
function goceshi(){
history.back();
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<a href="openhtml.html">back to index</a>
<button id="btn" οnclick="goob()">button</button>
<script>
function goob(){
history.forward();
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button id="btn" οnclick="getLoc()">button</button>
<p id="ptime"></p>
<script>
function getLoc(){
document.getElementById("ptime").innerHTML= window.location.hostname;
}
</script>
</body>
</html>
返回:
localhost
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button id="btn" οnclick="getLoc()">button</button>
<p id="ptime"></p>
<script>
function getLoc(){
document.getElementById("ptime").innerHTML= window.location.pathname;
}
</script>
</body>
</html>
返回:
/untitled1/ceshi.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button id="btn" οnclick="getLoc()">button</button>
<p id="ptime"></p>
<script>
function getLoc(){
document.getElementById("ptime").innerHTML= window.location.port;
}
</script>
</body>
</html>
返回:63342(端口)
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button id="btn" οnclick="getLoc()">button</button>
<p id="ptime"></p>
<script>
function getLoc(){
document.getElementById("ptime").innerHTML= window.location.href;
}
</script>
</body>
</html>
返回地址: http://localhost:63342/untitled1/ceshi.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button id="btn" οnclick="getLoc()">button</button>
<p id="ptime"></p>
<script>
function getLoc(){
location.assign("http://www.jikexueyuan.com");
}
</script>
</body>
</html>
用来做屏幕适配:
document.write("可用高度:"+screen.availHeight+",可用高度"+screen.availWidth);
document.write("高度"+screen.height+"宽度:"+screen.width);
输出:可用高度:768,可用高度1304高度768宽度:1366