For anyone having issues in 2020 this is what I set up the other day and it works fine.
Facebook:
Give your Facebook button an ID of facebook-button
:
Add the follwing code snippet to the body code of the page in question:
<script>
const facebookButton = document.getElementById('facebook-button');
facebookButton.setAttribute('target', '_blank');
facebookButton.setAttribute(
'href',
`https://www.facebook.com/sharer/sharer.php?u=${window.location.href}`
);
</script>
Twitter:
Give your Twitter button an ID of twitter-button
:
Add the follwing code snippet to the body code of the page in question:
<script>
const twitterButton = document.getElementById('twitter-button');
twitterButton.setAttribute('target', '_blank');
twitterButton.setAttribute(
'href',
`https://twitter.com/share?url=${window.location.href}`
);
</script>
Linkedin:
Give your Linkedin button an ID of linkedin-button
:
Add the follwing code snippet to the body code of the page in question:
<script>
const linkedinButton = document.getElementById('linkedin-button');
linkedinButton.setAttribute('target', '_blank');
linkedinButton.setAttribute(
'href',
`https://www.linkedin.com/shareArticle?mini=true&url=${window.location.href}&title=${document.title}`
);
</script>