How can do the same function in javascript that is document.location.pathname - except with the referrer? so something like document.referrer.pathname?
Thanks.
The pathname property of the Location interface is a string containing the path of the URL for the location, which will be the empty string if there is no path.
The referrer property returns the URL of the document that loaded the current document.
window.location.pathname returns the path and filename of the current page. window.location.protocol returns the web protocol used (http: or https:) window.location.assign() loads a new document.
The Location pathname property in HTML is used to set or return the pathname of a URL. The Location pathname property returns a string which represents the pathname of the URL. Syntax: It returns the pathname property.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With