HTML code redirect code
So, I did this code a while ago for random events on my site. The code works fine, but I wanted to add a timer.
What I need is when the user refreshes / enters the page, you are redirected, then I want him to redirect again to the same page every X seconds.
<script>
var test = Math.floor(Math.random() * 1) <= 1;
if (test) {
window.location = "URL";
}
</script>
+3
source to share
3 answers
Without timer:
If you want to redirect the user, you can use this line in your script:
window.location = "URL";
When a user enters or updates the site, redirect it.
With timer:
A) Once
Note . You can also use setTimeout
.
var timer = setInterval(function(){
clearInterval(timer);
window.location = "URL"
},3000);
C) endless
setInterval(function(){
window.location = "URL"
},3000);
0
source to share