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
How to check a variable is undefined in JavaScript?
How to change text color on click using JavaScript?
Highlight and get the details of table row on click using JavaScript
How to the length of the longest word in the provided sentence?
What's the difference between let and var?
How to join string with number in JavaScript?