Skip to content

Instantly share code, notes, and snippets.

@derryberni
Last active May 17, 2019 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derryberni/2e1c421430e330af28a90d3b9fa9d47d to your computer and use it in GitHub Desktop.
Save derryberni/2e1c421430e330af28a90d3b9fa9d47d to your computer and use it in GitHub Desktop.
Sharing Social Media// source https://jsbin.com/zahajaruci
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Sharing Social Media</title>
</head>
<body>
<button onclick="shareFacebook()">
Facebook
</button>
<button onclick="shareTwitter()">
Twitter
</button>
<button onclick="shareLinkedin()">
Linkedin
</button>
</html>
var dtkShare = {
url : "https://detik.com/",
text :"it's description for Detik.com"
}
function shareFacebook() {
var FacebookUrl = 'https://www.facebook.com/sharer/sharer.php?u=' + dtkShare.url;
showTab(FacebookUrl);
}
function shareTwitter(){
var TwitterUrl = 'https://twitter.com/intent/tweet?url=' + dtkShare.url + '&text=' + dtkShare.text;
showTab(TwitterUrl);
}
function shareLinkedin(){
var LinkedinUrl = 'https://www.linkedin.com/shareArticle?mini=true&url=' + dtkShare.url + '&title=' + dtkShare.text;
showTab(LinkedinUrl);
}
function showTab(urlShare){
//if pwa
if (window.matchMedia('(display-mode: standalone)').matches) {
window.location.href = urlShare;
} else {
//if mobile / desktop
window.open(urlShare,
'share-dialog',
'width=800,height=600'
);
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment