Get current URL with jQuery

Below tutorial explains,how to get the current URL of the page in JavaScript or JQUERY. The current URL represents a full page URL. We can also get current domain, hostname, pathname, protocol, port, hash and other components of the full page URL. You can also redirect the current page URL to other addresses with the properties of window.location object.

Methods to get different components of the URL #returns host

window.location.hostname #returns hostname

window.location.path #return path

window.location.href #returns full current url

window.location.port #returns the port

window.location.protocol #returns the protocol

We take a sample URL URL to understand the components of a URL. The current URL comprises the following components.

Example URL :

host www. getsourcecodes .com:8082

hostname www. getsourcecodes .com

port 8082

protocol http:

pathname index.php

href http://www. getsourcecodes .com:8082/index.php#tab2

hash #tab2

search ?foo=789

Usage :

Tags : Get current URL with jQuery,how to get hostname in jQuery, how to get host in jQuery,how to get port in jQuery ,how to get protocol in jQuery, ,how to get pathname in jQuery, how to get href in jQuery, how to get url after hash in jQuery,,how to get url search query in jQuery,How to get current URL, parameters and Hash

Add a Comment

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