0

How can I do a redirect to another HTML page after a user reloads the page? I don't want to do it automatically, therefore can't use http-equiv="refresh". Any ideas? Thanks

Neli
  • 532
  • 1
  • 3
  • 15

3 Answers3

2

Below function will make sure, If your page is loaded for first time or its a page refresh. Then you may add your code accordingly.

<form name="refreshForm">
<input type="hidden" name="visited" value="" /> 
 // above Hidden field to store value of your page load status
</form>

function checkRefresh()
{
    if( document.refreshForm.visited.value == "" )
    {
        // This is a fresh page load
        document.refreshForm.visited.value = "1";
    }
    else
    {
             // This is a page refresh    
            window.location.replace("http://google.com");
             // Or , Use either of them
            window.location.href = "http://google.com";
    }
} 
Mayank Pathak
  • 3,621
  • 5
  • 39
  • 67
0
<meta http-equiv="refresh" content="30; ,URL=http://www.metatags.info/login">

content = 30 // after 30 second ur page will redirect to this URL=http://www.metatags.info/login" url

Umakant Mane
  • 1,001
  • 1
  • 8
  • 9
0

You could trigger an event on when the F5 key is pressed:-

document.onkeydown = fkey;
document.onkeypress = fkey
document.onkeyup = fkey;

var wasPressed = false;

function fkey(e){
        e = e || window.event;
       if( wasPressed ) return; 

        if (e.keyCode == 116) {
             window.location = "http://www.yoururl.com";;
            wasPressed = true;
        }
 }
Tony Hensler
  • 1,482
  • 5
  • 15
  • 30
  • But this is not the only way to reload a page. You can use ctrl + R or ctrl + shift + R or just click on url on browser and then enter or you can press the reload button on browser! As per Mozilla and other docs, they said user have the right to reload and no one can block them. And there are some security issues on page redirection after reload. – mrgreen May 16 '23 at 06:06