簡體   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