Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 15
    They are not "methods" of window.location, but properties, and here we have an example: var stringPathName = window.location.pathname. Commented Jul 22, 2014 at 22:18
  • 1
    @FabioC. You can remove it by substring. However, it may be useful when you want to use to redirect document.location = "/page.html"; will redirect to root page page.html Commented Dec 23, 2016 at 5:11
  • 1
    Keep in mind ie9 pathname does not have a leading slash, so it could be index.html.
    – AJcodez
    Commented Jun 5, 2017 at 14:55
  • 7
    This answers more than just the question stated. In fact, I searched probably around a month ago for a good way to get one or more specific parts out of the URL string (I think it was probably the current page I was trying to get), and even though other questions were more on-target, their answers were not as useful and straightforward for that purpose as this one. Commented Jan 7, 2019 at 7:10
  • 2
    One quick suggestion though: In the basic URL structure described above, there's a spot for search, but in the list of descriptions below, it's called a query. Maybe either they can be reconciled, or further explanation can be added. Commented Jan 7, 2019 at 7:11