How to current URL, HOST and URL attributes using JavaScript or jQuery?

JavaScript
alert(window.location.host);     //returns www.golangprograms.com
alert(window.location.hostname); //returns www.golangprograms.com
alert(window.location.pathname); //return /javascript-and-jquery-examples/how-to-current-url-host-and-url-attributes-using-javascript-or-jquery.html
alert(window.location.href);     //returns http://www.golangprograms.com/javascript-and-jquery-examples/how-to-current-url-host-and-url-attributes-using-javascript-or-jquery.html
alert(window.location.port);     //returns null
alert(window.location.protocol);  //returns http:
jQuery
$(document).ready(function () {
	alert($(location).attr('host')); //returns www.golangprograms.com
	alert($(location).attr('hostname')); //returns www.golangprograms.com
	alert($(location).attr('pathname')); //return /javascript-and-jquery-examples/how-to-current-url-host-and-url-attributes-using-javascript-or-jquery.html
	alert($(location).attr('href')); //returns http://www.golangprograms.com/javascript-and-jquery-examples/how-to-current-url-host-and-url-attributes-using-javascript-or-jquery.html
	alert($(location).attr('port')); //returns null
	alert($(location).attr('protocol')); //returns http:
});
Most Helpful This Week