[英]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.