Last active
May 17, 2019 09:32
-
-
Save derryberni/2e1c421430e330af28a90d3b9fa9d47d to your computer and use it in GitHub Desktop.
Sharing Social Media// source https://jsbin.com/zahajaruci
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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()"> | |
</button> | |
<button onclick="shareTwitter()"> | |
</button> | |
<button onclick="shareLinkedin()"> | |
</button> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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