admin管理员组文章数量:1415684
I am looking for a solution with javascript to check if the previous page is not extranal.
With this check I want return true or false so I can use this for another function.
What I have tried is to get the previous URL with history.go(-1)
but this is undefined.
I am happy if I can get the previous URL so far.
Hope somebody can help me out with this.
I am looking for a solution with javascript to check if the previous page is not extranal.
With this check I want return true or false so I can use this for another function.
What I have tried is to get the previous URL with history.go(-1)
but this is undefined.
I am happy if I can get the previous URL so far.
Hope somebody can help me out with this.
Share Improve this question edited Jun 15, 2023 at 8:04 Penny Liu 17.6k5 gold badges86 silver badges108 bronze badges asked Feb 2, 2022 at 23:19 BenBen 731 gold badge1 silver badge7 bronze badges 1-
1
In JS it's
document.referrer
. – CherryDT Commented Feb 2, 2022 at 23:23
2 Answers
Reset to default 1Simply use to know previous URL
document.referrer
document.write(document.referrer);
You can use document.referrer
to get the URL of the previous page.
To check whether it is external or not, you can parse it with the URL
constructor and pare its origin.
const previousURL = document.referrer;
const isPreviousURLExternal = new URL(previousURL).origin == new URL(location).origin;
console.log(isPreviousURLExternal)
本文标签: Get previous URL with javascriptStack Overflow
版权声明:本文标题:Get previous URL with javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745213744a2648039.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论