Reputation: 3
So I'm trying to make it so I go to another website after a certain number of seconds, however it doesn't appear to be working. I would expect my code (below) to go to youtube for 10 seconds and then it would change into google. What is the problem? Much appreciated.
window.location.assign("http://www.youtube.com");
setTimeout(doSomething, 10000);
function doSomething()
{
window.location.replace("http://www.google.com");
}
Upvotes: 0
Views: 52
Reputation: 3532
Once the browser leaves the page your JavaScript stops processing too. You cant go to another site and then continue to run your JavaScript.
Upvotes: 1
Reputation: 318342
window.location.assign("http://www.youtube.com");
redirects to Youtube, so anything after that line is not executed as you're now on Youtube ?
Upvotes: 3