//retrieve the previous page
var previouspage = window.sessionStorage.getItem("page"):
// if thee is no previous page you are on the first page
if (previousPage == undefined){
//do something if you want, this means it's the first page the user is seeing
}
//get current page address
var currentPage = window.location.href;
//store it
window.sessionStorage.setItem("page",currentPage);
//check if the previous page is the one you wanted.
if (previousPage == "the_page_you_wanted"){
// do something.
}
1条答案
按热度按时间7d7tgy0s1#
如果你想要一些内置的东西,你可以使用
document.referrer
来获取以前的URL。但是它可能不可靠,无法满足你的需求。更多信息here,here和here另一个非常简单的选择是将当前页面名称存储在会话存储中,读取它,然后决定下一步做什么。
LocalStorage vs SessionStorage