首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使后退按钮转到上一页而不是跳过内部链接?

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

Stack Overflow用户
提问于 2016-11-20 20:38:32
回答 1查看 614关注 0票数 1

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

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-20 20:53:03

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

​

代码语言:javascript
复制
<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>

​

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40709112

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档