Javascript 如何通过单击浏览器';s后退按钮
如何使用javascript阻止用户在按下浏览器后退按钮后返回到以前的页面。 非常感谢您的建议** 谢谢和问候Javascript 如何通过单击浏览器';s后退按钮,javascript,Javascript,如何使用javascript阻止用户在按下浏览器后退按钮后返回到以前的页面。 非常感谢您的建议** 谢谢和问候 Bannister通过使用javascript,您可以做到这一点 参考这个, 这可能会帮助你谢天谢地,这是不可能的。您无法停止用户的后退按钮的工作,但从技术上讲,您可以多次更改url,甚至尝试使用后退按钮导航都是毫无意义的 // treat the URL changes as a non-external page (the page won't reload) document.
Bannister通过使用javascript,您可以做到这一点 参考这个,
这可能会帮助你谢天谢地,这是不可能的。您无法停止用户的后退按钮的工作,但从技术上讲,您可以多次更改url,甚至尝试使用后退按钮导航都是毫无意义的
// treat the URL changes as a non-external page (the page won't reload)
document.location.href += "?";
// Fill up the browser's history
for(var i = 0; i < 100; i++){
document.location.href += "a";
document.location.href = document.location.href.substring(0, document.location.href.length-1)
}
//将URL更改视为非外部页面(该页面不会重新加载)
document.location.href+=“?”;
//填写浏览器的历史记录
对于(变量i=0;i<100;i++){
document.location.href+=“a”;
document.location.href=document.location.href.substring(0,document.location.href.length-1)
}
这将使用相同的页面填充浏览器的历史记录,有效地禁用任何实际用途的“后退”按钮。在页面加载时使用此按钮,它将停止用户从其放置的页面返回
<script type = "text/javascript">
function changeHashOnLoad() {
window.location.href += "#";
setTimeout("changeHashAgain()", "50");
}
function changeHashAgain()
{
window.location.href += "1";
}
var storedHash = window.location.hash;
window.setInterval(function () {
if (window.location.hash != storedHash) {
window.location.hash = storedHash;
}
}, 50);
</script>
函数changehasonload(){
window.location.href+=“#”;
setTimeout(“changehashtreach()”,“50”);
}
函数changehash()
{
window.location.href+=“1”;
}
var storedHash=window.location.hash;
window.setInterval(函数(){
if(window.location.hash!=storedHash){
window.location.hash=storedHash;
}
}, 50);
按下后退按钮时,为什么不确认用户操作
差不多
window.onbeforeunload = function(){
return "Message here";
}
它将防止用户意外单击后退、前进或关闭窗口并直接更改url 检查原因?是否要阻止用户查看这些页面?你的网站设计是否会导致加载这些页面会导致重复某些操作?请检查此项,阅读到目前为止你测试的内容的可能副本?提示是作为此网站的新用户签出此页面。:)链接不起作用。