---
title: "JavaScript - Get Portion of URL Path"  
description: "JavaScript - Get Portion of URL Path"  
author: "Royce Roy"  
published: 2013-03-12  
updated: 2013-03-12  
canonical: https://www.mindstick.com/forum/656/javascript-get-portion-of-url-path  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# JavaScript - Get Portion of URL Path

Hi Everyone!

What is the correct way to pull out just the [path](https://www.mindstick.com/articles/44333/4-expert-tips-on-how-to-pick-the-right-career-path) from a [URL](https://www.mindstick.com/forum/436/url-redirection) using [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)?

Example:\
I have URL\
http://www.somedomain.com/[account](https://www.mindstick.com/articles/33699/how-tech-is-disrupting-the-accounting-world)/[search](https://www.mindstick.com/articles/65368/best-smo-services-company-in-hyderabad-improve-search-rankings)?filter=a#top\
but I would just like to get this portion\
/account/search

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

Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)\

## Replies

### Reply by AVADHESH PATEL

Hi Royce!

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

// If URL is http://www.somedomain.com/account/search?filter=a#top

window.location.pathname // /account/search

// For reference:

window.location.host // www.somedomain.com (includes port if there is one)\
window.location.hostname // www.somedomain.com\
window.location.hash // #top\
window.location.href // http://www.somedomain.com/account/search?filter=a#top\
window.location.port // (empty string)\
window.location.protocol // http:\
window.location.search // ?filter=a


---

Original Source: https://www.mindstick.com/forum/656/javascript-get-portion-of-url-path

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
