开发者

Javascript pathname referrer

开发者 https://www.devze.com 2023-03-16 13:14 出处:网络
How can do the same function in jav开发者_运维知识库ascript that is document.location.pathname - except with the referrer? so something like document.referrer.pathname?

How can do the same function in jav开发者_运维知识库ascript that is document.location.pathname - except with the referrer? so something like document.referrer.pathname?

Thanks.


No, you can only extract needed part manually:

document.referrer.replace(/^[^:]+:\/\/[^/]+/, '').replace(/#.*/, '')


You can extract the pathname from the document.referrer and parse it with new URL() with the following code

const url = new URL(document.referrer)
url.pathname

Be sure to polyfill URL for IE 10 and below, easily done with https://polyfill.io/v3/polyfill.js?features=URL


you can use document.referrer to obtain the URL of the referring document. Is that what you mean??

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号