How to get current url Jquery vanilla Javascript

satinder singh / Updated : / 2 Comments

Overview: 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 getQueryString=window.location.search //?id=5&name=SatinderSingh
//*

 

2 comments on “How to get current url Jquery vanilla Javascript”


Post Comment


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