我可以检查window.history.back()将用户带到哪个站点? [英] can I check what site window.history.back() will bring the user to?
问题描述
在我的一个网页中,我想经过一些计算将用户返回到上一页,但前提是上一页是我网站上的页面。
in one of my webpages I want to send the user back to the previous page after some computation, but only if the previous page was a page from my website.
所以我想知道是否有一种简单的方法来检查该内容?
So I am wondering if there is an easy way to check that?
感谢您的任何输入!
推荐答案
不过,您可以使用以下两种方法检查到达当前页面的方式:
You can however check how you arrived at the current page by using 2 methods:
文档。 Referrer
,但这仅在用户未阻止的情况下有效,并且为您提供了一些有限的信息。
一种更可靠的方法可能是在URL或 SESSION
变量中设置有关上一页的某些信息。
document.referrer
, but that only works if the user didn't block that, and gives you some limited info.
A more robust method might be to set some information about the previous page in either the URL, or in a SESSION
variable.
这篇关于我可以检查window.history.back()将用户带到哪个站点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!