我想取消由 javascript 函数启动的重定向。javascript 在 5 秒内重定向到主页,并显示为错误消息。我想通过鼠标单击错误消息来取消重定向。请提供任何帮助。
PHP代码:
<div id="error">
<?php
//redirect
if (isset($_GET['err'])){
if ($_GET['err'] == 1){
echo "You are successfully logged out. You will be redirected to the home page in <strong><span id = 'seconds'> 5 </span> </strong> seconds.";
}elseif($_GET['err'] == 0){
echo "Your session has been expired. Please login again.!";
}
}
?>
</div>
Javascript:
<script>
var seconds = 5;
var err = <?php echo $_GET['err'] ; ?>;
if (err == 1){
setInterval(
function(){
if (seconds <= 1) {
window.location = 'http://****.***.***.***/***';
}
else {
document.getElementById('seconds').innerHTML = --seconds;
}
},
1000
);
}
</script>