-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathshare.js
27 lines (21 loc) · 1014 Bytes
/
share.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Sharing Post to different social media platform
document.addEventListener('DOMContentLoaded', function () {
const shareButtons = document.querySelectorAll('.share-button');
const shareContent = () => {
const url = encodeURIComponent(window.location.href);
const text = encodeURIComponent(document.title);
const shareUrls = {
// facebook: `https://www.facebook.com/sharer/sharer.php?u=${url}`,
twitter: `https://twitter.com/intent/tweet?url=${url}&text=${text}`,
linkedin: `https://www.linkedin.com/shareArticle?mini=true&url=${url}&title=${text}`,
reddit: `https://www.reddit.com/submit?url=${url}&title=${text}`,
whatsapp: `https://api.whatsapp.com/send?text=${text} ${url}`
};
for (const platform in shareUrls) {
window.open(shareUrls[platform], '_blank');
}
};
shareButtons.forEach(button => {
button.addEventListener('click', shareContent);
});
});