嘗試使用jQuery將頁面重定向到另一個域。我注意到,如果我嘗試與其他網址重定向,但不會重定向到我想要重定向到的特定網址。也注意到鏈接工作,如果我倒計時之前點擊它,但倒計時爲零時不起作用。這裏是我的HTML和jQuery代碼jquery與倒計時重定向卡在零
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Redirect Site</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function() {
var delay = 10 ;
var url = "http://www.wordoflifedubuque.org";
function countdown() {
setTimeout(countdown, 1000) ;
$('#countmesg').html("Redirecting in " + delay + " seconds.");
delay --;
if (delay < 0) {
window.location = url ;
delay = 0 ;
}
} countdown() ;
});
</script>
<style>
#countmesg{
font-size: 2em;
text-align: center;
font-weight: bold;
}
.header{background-color: black;}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-12 header">
<img src="logo.png" class="res">
</div>
</div>
<div class="row">
<div class="col-sm-12">
<h3>This website has moved, click the link <a href="http://www.wordoflifedubuque.org">http://wordoflifedubuque.org</a> to go to the new site or be redirected automatically.</h3>
<div id="countmesg"></div>
</div>
</div>
</div>
</body>
</html>
謝謝蒂姆。這工作:) – Olucrown