我有幾個頁面重定向代碼(做工精細)如下:如何用點擊取消頁面的重定向?
<meta http-equiv="refresh" content ="42; url=http://my url.html#">
但我想在自動重定向到被取消或延誤,如果用戶點擊頁面的任何一點。 我應該使用哪些代碼? 感謝
我有幾個頁面重定向代碼(做工精細)如下:如何用點擊取消頁面的重定向?
<meta http-equiv="refresh" content ="42; url=http://my url.html#">
但我想在自動重定向到被取消或延誤,如果用戶點擊頁面的任何一點。 我應該使用哪些代碼? 感謝
這裏是點擊頁面上的任何位置代碼:
<script>
$('html').click(function() {
alert("ok"); // Do whatever you want here, just replace. Since i dont know your code. So i can help you till this point.
});
</script>
<head></head>
插入一個簡單的JS-定時刪除您<meta http-equiv="refresh">
和使用window.location
後指用戶已加載頁面。
var timeVar = setInterval(function() {myTimer()}, 1000);
var t = 9;
function myTimer() {
if (t>0) {
document.getElementById("timer").innerHTML = t; \t \t
t--;
}
else { window.location = 'what/ever/you/are/workingon.html'; }
}
function StopFunction() { clearInterval(timeVar); }
<p>Redirecting in <span id="timer" style="font-weight: bold;">10</span>Seconds.</p>
<p onclick="StopFunction();" style="cursor: pointer; ">Cancel!</p>
用戶將加載你的頁面,而不是取消計時器時,被重定向到您定義的頁面。如果停止計時器,用戶將不會被重定向並留在頁面上。 br
不要使用META,使用Javascript'setTimeout()'。然後添加一個取消定時器的點擊處理程序。 – Barmar
使用你現在提到的Javascript(正常工作)。但我不知道代碼或它在哪裏創建點擊處理程序。我現在用來重定向的代碼是:我現在使用的是Javascript重定向代碼(也可以正常工作) //www.myurl.html';",15000); - > – whispert