I am using a Javascript redirect to redirect visitors after X seconds. However, there is also a link on the page that takes the visitor to the same page. I would like to stop the redirection if the visitors clicks on the link first.
Please note that ,the link is opening in the new window when clicked but the javascript redirect opens in the same window.
This is the code am using in my HTML Page ,
Javascript redirect code:
<script>
<!--
timeout = '5000'; // milliseconds/1000th of a sec
window.onload = setTimeout(myRedirect, timeout); // ensure we load the whole page
function myRedirect() {
window.location = "http://www.mypage.com/page1.html";
}
//-->
</script>
and there is this link which opens in new window:
<a href="http://www.mypage.com/page2.php" target="_blank">Click Here</a>
any ideas on how i can achieve this?
store your timeout call in a variable.
and when you want it cancelled, clear that timeout in that variable: