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
Write a function that splits an array into groups the length of size and returns them as a two-dimensional array
Image Rollover Using onMouseOver and onMouseOut
JavaScript HTML5 Validation for name and email field
ES6 method of declaration multiple variables in one line
Example to take user input and display on screen using JavaScript
Using jQuery add new table row on click