My Javascript ain't so hot, so before I get into some messy string operations, I thought I'd ask:
If the current url is: "http://stackoverflow.com/questions/ask"
What's a good way to to just get: "/questions/ask" ?
Basically I want a string that matches the Url without the domain or the "http://"
Answer: Use the window. location. href Property location. href property to get the entire URL of the current page which includes host name, query string, fragment identifier, etc.
window.location.href returns the href (URL) of the current page. window.location.hostname returns the domain name of the web host. window.location.pathname returns the path and filename of the current page.
The steps to identifying the domain name from a web address are: Start from the far left of the address and read right. Ignore the "http://" or "https://" (if there is one) and simply read everything up to the next "/" character.
Definition and Usage The origin property returns the protocol, hostname and port number of a URL.
alert(window.location.pathname);
Here's some documentation for you for window.location
.
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