javascript 在浏览器中更改后退按钮 URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30526811/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change the back button URL in browser
提问by MM PP
I want to disallow the visitor go back in browser, I tried the code here (How to disable back button in browser using javascript) and works well, but I want to make somenthing more useful for my application. I want to change the back url.
我想禁止访问者在浏览器中返回,我在这里尝试了代码(如何使用 javascript 在浏览器中禁用后退按钮)并且运行良好,但我想让一些东西对我的应用程序更有用。我想更改后面的网址。
So, if the back URL is mywebsite.com/admin/add_new_article.php I want to change the back URL to mywebsite.com/admin/index.php
因此,如果返回 URL 是 mywebsite.com/admin/add_new_article.php 我想将返回 URL 更改为 mywebsite.com/admin/index.php
Thank you all!
谢谢你们!
回答by NETCreator Hosting
<script type="text/javascript">
history.pushState(null, null, '<?php echo $_SERVER["REQUEST_URI"]; ?>');
window.addEventListener('popstate', function(event) {
window.location.assign("http://www.yoururl.com/");
});
</script>
Hope it helps!
希望能帮助到你!