سؤال

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");
}
هل كانت مفيدة؟

المحلول

window.location.assign("http://www.youtube.com");

redirects to Youtube, so anything after that line is not executed as you're now on Youtube ?

نصائح أخرى

Once the browser leaves the page your JavaScript stops processing too. You cant go to another site and then continue to run your JavaScript.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top