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
jQuery get the coordinates of div clicked
Using jQuery add new table row on click
Write a function that splits an array into groups the length of size and returns them as a two-dimensional array
How to change text color on click using JavaScript?
How to get selected text from a select box using jQuery?
How to the length of the longest word in the provided sentence?