How to implement a scheduled task on the code?

I need to when I opened the program I have not worked the code,and after 6000млс, I started to run the code without any delays,and after 10000 all stopped working code.

Code
let url = window.location.hostname;

if (url !== "toster.ru") {
window.location.href = "https://www.toster.ru";
}
March 19th 20 at 09:28
3 answers
March 19th 20 at 09:30
setTimeout(function(){
//your code here
}, 6000)
Answered above) - Denis.Oberbrunner72 commented on March 19th 20 at 09:33
When I wrote the answer above was not yet on the page because I opened the page before... - dorthy_Abshire commented on March 19th 20 at 09:36
@dorthy_Abshire, Answered above in comments) ( not to copy ) - Denis.Oberbrunner72 commented on March 19th 20 at 09:39
March 19th 20 at 09:32
Something like that?

setTimeout(() => {
 setInterval(() => {
 let url = window.location.hostname;

 if (url !== "toster.ru") {
 window.location.href = "https://toster.ru";
}
 }, 4000)
}, 6000);
March 19th 20 at 09:34
If you are trying to do to the user who left your page is back there with a gun, and if not gone - it is not returned, then this will not work.
If the user left (url has changed) you already did "force" will not return.
You can only send the user to another site, if it is very long sits on your and is not going anywhere.

Find more questions by tags JavaScript