2013-08-27 24 views
0

我有幾個頁面重定向代碼(做工精細)如下:如何用點擊取消頁面的重定向?

<meta http-equiv="refresh" content ="42; url=http://my url.html#"> 

但我想在自動重定向到被取消或延誤,如果用戶點擊頁面的任何一點。 我應該使用哪些代碼? 感謝

+1

不要使用META,使用Javascript'setTimeout()'。然後添加一個取消定時器的點擊處理程序。 – Barmar

+0

使用你現在提到的Javascript(正常工作)。但我不知道代碼或它在哪裏創建點擊處理程序。我現在用來重定向的代碼是:我現在使用的是Javascript重定向代碼(也可以正常工作) //www.myurl.html';",15000); - > – whispert

回答

0

這裏是點擊頁面上的任何位置代碼:

<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> 
+0

我只使用META代碼abobe,沒有別的。你的代碼會考慮它嗎? – whispert

+0

我不這麼認爲,META會幫助你。最好的方法是使用javascript –

+0

已經做了,它工作。感謝你的幫助! – whispert

0
  1. 從文件<head></head>
  2. 插入一個簡單的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

相關問題