繁体   English   中英

如何使后退按钮转到上一页而不是跳转内部链接?

[英]How do I make the back button go to the previous page instead of jumping internal links?

目前,我的浏览器后退按钮是在我的网站上跳转内部链接。 每个部分都有一个ID,导航将跳转到具有相应ID的部分。 我希望我的网站回过头来说Google,如果这是用户来自的地方,而不是在我的页面上跳转。

我该怎么做呢? 有没有办法控制浏览器后退按钮在我的网站上做什么?

此答案已经过修改,以显示正确的信息。 通过更改A元素的运行方式,它不会向URL添加#,当他们点击后退按钮时,他们将被带到他们访问您的网站之前所在的页面(只要您的网站是一个页面)。

 <head> <script type="text/javascript" src="//code.jquery.com/jquery-2.1.4.js"></script> </head> <!--These are your links that will take the user to each part of the page. Change the value in the onclick function to the name of your div--> <a href="Javascript:void(0);" onclick="goToByScroll('div1')">Click here to go to Div 1</a> <a href="Javascript:void(0);" onclick="goToByScroll('div2')">Click here to go to Div 2</a> <!--Add ID attributes to your divs, this is what you will put in the goToByScroll Onclick value.--> <div id="div1" style="margin-top: 700px"> <!--Div 1 Info--> Div 1 </div> <div id="div2" style="margin-top: 700px"> <!--Div 2 info--> Div 2 </div> <!--This is the JS function. I've added in a smooth scrolling technique to make it not choppy.--> <script type="text/javascript"> function goToByScroll(id){ $('html,body').animate({scrollTop: $("#"+id).offset().top},'slow'); } </script> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM