HTML <meta>
<html>
<head>
<title>Relocation</title>
<meta http-equiv="refresh" content="3; URL=file:///C:/Users/Administrator/Desktop/test.html" />
</head>
<body>
</body>
</html>
JavaScript
JavaScript实现重定向主要是利用了location对象。
下面这个例子证明了:window.location === document.location === location(“===”表示全等)。
注意:body只能是document.body。
<html>
<head>
<title>Certify location equal</title>
</head>
<body>
<script type="text/javascript">
document.body.innerHTML += (location + "<br/>");
if(document.location === window.location) {
document.body.innerHTML += "document.location = window.location<br/>";
} else {
body.innerHTML += "document.location != window.location<br/>";
}
if(document.location === location) {
document.body.innerHTML += "document.location = location<br/>";
} else {
document.body.innerHTML += "document.location != location<br/>";
}
</script>
</body>
</body>
JavaScript setTimeout
<script type="text/javascript">
setTimeout(function(){
location = "file:///C:/Users/Administrator/Desktop/test.html";
}, 3000);
</script>
JavaScript setInterval
<script type="text/javascript">
var t = 5;
setInterval(function(){
document.body.innerHTML += (t-- + "<br/>");
if(t == 0) {
location = "file:///C:/Users/Administrator/Desktop/test2.html";
}
}, 1000);
</script>
location 注意点
location="file:///……"
或location="http:///……"
“协议前缀”很关键,如果有这些“协议前缀”就相当于在浏览器地址栏中输入相应地址。但如果没有这些前缀,则location="……"
等价于访问当前路径的相对地址。