Search code examples
javascriptphpfunctionmethodshref

how to redirect with js and alert if turn in previous page?


i want to redirect to a php page for example example.php and make possible not to turn back to the first page,if try to turn i must alert the user.i dont want do delete the page from hisotry. Any of that insrtuction:

    window.open('example.php','_self') or
    location.href:example.php or
    header("location: example.php) or
or location.replace('example.php;)

cant do what i want. is there any javascript method or php function to make that? Thanks in advance!


Solution

  • In Javascript you can use location.replace() to assign a new url - it forgets the previous location ( removes from history )

    location.replace( 'example.php' );
    

    For reference, try MDN