Javascript pathname referrer
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??
精彩评论