How to get current url Jquery vanilla Javascript

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
//*

 

Share:    
Satinder Singh

Hi all, am Founder and Author of Codepedia.info, also atypical polyglot programmer from Bombay, India. I have a passion to create, solve, and deploy software applications.
       ForEach ( minute in MyLife ) { myExperience++ ; }



Post Comment


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