I've been trying really hard to make the Facebook share button work, but no luck. I'd like to have the same code on ALL my pages, so I need to be able to dynamically get the current page url and append it to the Facebook share URL.
The best I could come up with is the following:
<a href="" onclick="window.open('http://www.facebook.com/share.php?u=' +
encodeURIComponent(location.href))">Share this page</a>
https://jsfiddle.net/08x2sufs/2/
However, as you can see from the jsFiddle demo, the link does take us to a Facebook share page, but there is no page to share.
Thank you for your help.
I would use the following approach:
<a href="" id="fb_share">Share this page</a>
<script>
window.onload = function() {
fb_share.href ='http://www.facebook.com/share.php?u=' + encodeURIComponent(location.href);
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With