How to get current url Jquery vanilla Javascript


JavasSript get current url: Get current web page URL in jQuery and javascript. This is most common think while developing websites where we need to fetch page URL for performing further function i.e get pathname, hostname, query string etc.

Example: My page URL is  http://localhost:2239/Default2.aspx?id=5&name=SatinderSingh

var getCurrentURL =window.location.href; //http://localhost:2239/Default2.aspx?id=5&name=SatinderSingh
var getHostname=window.location.hostname; //localhost
var getPathName=window.location.pathname  // Default2.aspx
var getPortNo=window.location.port        // 2239
var //?id=5&name=SatinderSingh 

Thank you for reading, pls keep visiting this blog and share this in your network. Also, I would love to hear your opinions down in the comments.

PS: If you found this content valuable and want to do a favor, then Buy me a coffee

Subscribe to our newsletter

Get the latest and greatest from Codepedia delivered straight to your inbox.

Post Comment

Your email address will not be published. Required fields are marked *


  1. vijayalavan 10/20/2017 11:57:23
    Hi Satinder Singh, I'm a learner... Thanks for ur support
  2. Satinder singh 10/26/2017 06:54:31
    Vijayalavan you most welcome