Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's an easy way to get the url in the current window minus the domain name?

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://"

like image 430
Kenji Crosland Avatar asked Oct 18 '10 00:10

Kenji Crosland


People also ask

How do I get the current URL of a window?

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.

How do I get the current domain in HTML?

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.

How do you read a domain name from URL?

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.

What does Window location Origin return?

Definition and Usage The origin property returns the protocol, hostname and port number of a URL.


1 Answers

alert(window.location.pathname); 

Here's some documentation for you for window.location.

like image 157
user113716 Avatar answered Sep 24 '22 00:09

user113716