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"
});
});
Try window.location.href
$(document).ready(function() {
$(".share").hideshare({
link: window.location.href,
position: "top"
});
});
Try with window.location.href
or document.URL
object
$(document).ready(function() {
$(".share").hideshare({
link: window.location.href,
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 work
Use 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?
Commented
Jun 29, 2016 at 10:20
To get Current URL, you can use:
var pathname = window.location.pathname; // Returns path only
var url = window.location.href; // Returns full URL
window.location
to get the current URL.