如何重定向与js和警报,如果翻在前一页


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

我想重定向到一个php页面,例如example.php,并使可能不转回第一页,如果试图转我必须提醒用户。我不想从历史中删除这一页。任何指令:

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

不能做我想做的。有没有javascript方法或PHP函数来实现?提前感谢!

在Javascript中,你可以使用location.replace()来分配一个新的url -它会忘记以前的位置(从历史记录中删除)

location.replace( 'example.php' );

参考MDN