Does not redirect in Firefox

Asked

Viewed 77 times

-1

The following code is not working in Firefox.

 <script>
         function go(){
           document.write('<p align="center">AGUARDE O ENCERRAMENTO...</p>');
         } 
         setInterval("go();", 3000);
         setInterval(function () { location.href = 'sair.php'; }, 5000);
</script>
  • Welcome to stackoverlow. Please take a look at our help center

  • Even I do not understand any javascript understand what you are asking. Instead of voting to close it would not be better to try, first, to improve it by editing it or asking for clarification?

2 answers

3


Your code seems to have some errors, or rather it wouldn’t be the best way to do it.

setInterval will generate a repeat at a given interval. If you want to delay the redirect, use setTimeout, that counts a time and then executes the function at the end of that time, but only once.

function go()
{
   document.write('<p align="center">AGUARDE O ENCERRAMENTO...</p>');
   setTimeout(function () { 
     location.href = '/sair.php'; 
   }, 5000);
} 


go();

-3

When you use setInterval or setTimeout, the mode of executing a function is different, quotes in her call do not exist, as well as parentheses.

Thus:

function go(){
    document.write('AGUARDE O ENCERRAMENTO...');
}

setInterval(go, 3000);
setInterval(function(){
    location.href = 'sair.php'; 
}, 5000);
  • Why setInterval? if it is going to be redirected, why use a function that generates a repetition if something will be executed only once? And her statement is wrong. She can call the function on setInterval string.

  • I just used the example based on the original code, just adjusted what was the doubt itself.

  • Didn’t solve the problem, you just changed the syntax of the code, but it does the same thing.

  • Of course she can, it doesn’t mean that she should or that the string you commented on is correct (because you haven’t used align=center for years). Her approach is bad, I just fixed the non-working code based on her knowledge.

  • I didn’t understand a thing.

  • @Wallacemaxters managed to solve what I needed, the code I passed works on IE and Chrome less on FF so what you went through worked tbm on FF Jardel’s doesn’t seem to work so I made the marking.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.