Refresh only 1 time

Asked

Viewed 1,412 times

1

I’m doing the creation of a website and I need a force.

The problem is this, I need that when entering the site the same of a refresh, just as you enter it

I tried the code:

<meta http-equiv="refresh" content="1">

Meanwhile he stays in one looping infinity of refresh and I need this to happen only once.

  • Does a function Javascript for this, search for Location.Reload()

  • axo que precisa de um contador para parar o refresh

  • What problem do you want to solve by doing this? I’ve seen very few cases where this was really needed.

  • Really! I posted a suggestion that can meet but this has the face of gambiarra :)...

  • In real people it is my main error: https://answall.com/questions/333002/erro-na-galeria-images

  • 1

    So don’t do that, it’s a bad idea to have to reload the page just to fix something that’s already in trouble. You better focus on the other question to solve the problem.

Show 1 more comment

3 answers

1

You can create a function and apply a condition.

    window.onload = function() {
    if(!window.location.hash) {
        window.location = window.location + '#carregar';
        window.location.reload();
    }
}
  • 2

    That way, it will continue in an infinite loop of refresh

  • That’s right, I’ll update the answer.

0

Guy I believe is not a good solution make a refresh right after accessing the site.

But you can use the command:

location.reload();
  • It will continue in the looping. It will enter the page, reload, and look like this.

0

If there is no other way to fix your problem... or while not finding a solution ....

javascript step by step

  1. take the page url
  2. Check if there are any parameters in the url
  3. If there is no redirect to the page itself by adding a parameter.
  4. No redirect with parameter will not execute the script

    var url=window.location.href;
    var parametrosDaUrl = url.split("?")[1];
    
    if (!parametrosDaUrl){
    
       window.location = "parametrosDaUrl.html?stop=yes";
    
    }
    

Browser other questions tagged

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