Advertise with us

JavaScript - Get Portion of URL Path

Posted by  Royce Roy
 2636  View(s)
Rate this:

Hi Everyone!

What is the correct way to pull out just the path from a URL using JavaScript?

I have URL
but I would just like to get this portion

I am using jQuery if there is anything there that can be leveraged.

Thanks in advance

  1. Re: JavaScript - Get Portion of URL Path

    Hi Royce!

    There is a property of the built-in window.location object that will provide that.

    // If URL is

    window.location.pathname // /account/search

    // For reference:     // (includes port if there is one)
    window.location.hostname //
    window.location.hash     // #top
    window.location.href     //
    window.location.port     // (empty string)
    window.location.protocol // http:   // ?filter=a