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
Highlight and get the details of table row on click using JavaScript
JavaScript sort multi dimensional array on specific columns
Generate random password for form field on click using JavaScript
Using jQuery delete table row on click
How can I redirect the user from one page to another using jQuery or pure JavaScript?
Check if a string ends with the given target string