如何使用jquery检查和验证以前访问我们页面的url



我有一个拼图形式的静态页面,我想使用参数"if else"这样,我的页面可以查看,如果我的页面的url从我想要的网站点击。例如:。

如果我的结果页是通过这个网站访问的

https://example.com

https://example.com/result

但是,如果我的页面是通过这个站点访问的

https://example - 2. com

或不通过example.com站点,或直接访问example.com/result链接而不通过https://example.com

https://example.com/result没有显示任何东西

我可以实现这样的系统在我的静态页面只使用参数如果否则jquery?

可以使用

document.referrer

The Document.referrer property returns the URI of the page that linked to this page.(MDN)

你可以这样做

if (document.referrer != ""){
if (new URLPattern(document.referrer).hostname === new URLPattern(window.location.origin).hostname){
//show result 
}
}

相关内容

最新更新