简体   繁体   English

返回按钮到第一个访问的页面

[英]back button to first visited page

Apologies if my question sounds like a newbie question...but I could not find an appropriate answer. 抱歉,如果我的问题听起来像是一个新手问题,但我找不到合适的答案。

I am trying to create 2 back buttons on my website that would bring the visitor back : 1. to the very first page he visited on my website 2. to the previous site (not page) he visited - so the site that brought him to my site basically. 我正在尝试在我的网站上创建2个后退按钮,以将访问者带回:1.转到他在我的网站上访问过的第一页2.转到他访问过的上一个网站(而非页面)-因此将他引至我的网站基本上。

Is this feasible by any chance ? 这是可行的吗? And if so, can you please share your insights on the way to do it ? 如果是这样,您能否分享您的见解?

Many thanks in advance for any help ! 在此先感谢您的帮助!

Maybe you can do something like this: 也许您可以执行以下操作:

$(document).ready(function() {
   var sessionIsNew = sessionStorage.getItem('sessionIsNew');

   if (sessionIsNew == null) {
      sessionStorage.setItem('sessionIsNew', 'false');
      sessionStorage.setItem('entryUrl', window.location.href);
   }

}

// On click to your back button:
function backToEnrtryPage () {
    entryUrl  = sessionStorage.getItem('entryUrl');

    if (entryUrl != null) {
       window.location.href = entryUrl;
    }
}

More information about session in JavaScript 有关JavaScript中会话的更多信息

https://developer.mozilla.org/de/docs/Web/API/Window/sessionStorage https://developer.mozilla.org/de/docs/Web/API/Window/sessionStorage

You can do it by manupulating the browser history, so to move once backward through history, just do: 您可以通过控制浏览器的历史记录来做到这一点,因此只需在历史记录中向后移动一次即可:

window.history.back();

to back to initial entry page you can do somting like 返回初始输入页面,您可以像

var numberOfEntries = window.history.length;
window.history.go(- numberOfEntries );

the full api documentation from mozilla : https://developer.mozilla.org/en-US/docs/Web/API/History_API 来自mozilla的完整api文档: https : //developer.mozilla.org/en-US/docs/Web/API/History_API

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

相关问题 后退按钮需要重定向到上次访问的页面 - Back button needs to redirect to last visited page 从后退按钮访问页面时强制页面刷新 - Force a page refresh when page visited from back button 通过在Firefox中单击“后退”按钮来重新加载访问时的页面 - Reload the page when visited by clicking Back button in Firefox 如果页面首先被访问,如何操纵路线? - How to manipulate routes if the page is visited first? 链接回先前访问的页面时设置默认值? - Setting default value when linking back to previously visited page? React Router - Go 返回最后访问的页面,而不是默认组件 - React Router - Go back to the last page visited, and not the default component window.history.back()的任何替代方法,因为它每次我返回时都会重复访问的页面 - Any alternative to window.history.back() as it repeats the visited page every time I go back 隐藏jquery表单向导首页上的“后退”按钮的最佳方法是什么? - What's the best way to hide the 'back' button on the first page of jquery form wizard? 检查用户是否访问了页面? - Check if a user visited a page? “返回”按钮转到目标位置,然后返回到原始页面 - “back” button goes to destination then back to original page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM