jquery get location code example
Example 1: jquery get url
var currentURL = $(location).attr('href');
var currentURL = window.location.href;
Example 2: jquery get location of user
$("#find_btn").click(function () { //user clicks button
if ("geolocation" in navigator){ //check geolocation available
//try to get user current location using getCurrentPosition() method
navigator.geolocation.getCurrentPosition(function(position){
$("#result").html("Found your location <br />Lat : "+position.coords.latitude+" </br>Lang :"+ position.coords.longitude);
});
}else{
console.log("Browser doesn't support geolocation!");
}
});
Example 3: jquery get left position
var position = p.position();
var left = position.left; '<-- left value for p
Example 4: jquery get URL slug
var pathname = window.location.pathname;