标题说得很好。即我需要调用它来将用户带到他们所在的先前位置,但只有当它不会将他们带离我们的网站时。
EG
mysite.com/#/foo - >
mysite.com/#/bar - >
back is triggered - >
user ends back to mysite.com/#/foo
好像用户直接去的地方
mysite.com/#/bar - >
back is triggered - >
user is back to whatever site they were first in.
您可以使用简单的功能:
function returnBack(){
// If last visited page before this page is in your domain
if(document.referrer.indexOf(window.location.host) >= 0)
{
window.history.back()
}
else {
// If last page is not in your domain, do your logic here..
}
}