I am using javascript. How do I get the path of the current URL and assign it to my code? Here is my code :
$(document).ready(function() {
$(".share").hideshare({
link: "current_url",
position: "top"
});
});
Something like the following should do it:
$(document).ready(function() {
$(".share").hideshare({
link: location.href
position: "top"
});
});
The window.location (also can be referenced by location) property contains many utility functions related to the current page.
Such as window.location.hash for the anchor
or window.location.search for the query string
You can use the window.location.href or window.location.path expressions if you don't need the full url.
window.location.path don't work on the latest version of Chrome/Firefox - window.location.pathname however should workUse window.location.href or window.location.pathname expressions if you don't need the full url. I mean
$(document).ready(function() {
$(".share").hideshare({
link: "window.location.href/window.location.pathname",
position: "top"
});
});
window.location.href/window.location.pathname what is the difference?
window.locationto get the current URL.