$(document).ready(function() { $('.facebook-share-btn').click(function() { var url = encodeURIComponent(window.location.href); // 获取当前页面的URL var facebookUrl = 'https://www.facebook.com/sharer/sharer.php?u=' + url; window.open(facebookUrl, 'facebook-share-dialog', 'width=626,height=436'); return false; }); $('.twitter-share-btn').click(function() { var url = encodeURIComponent(window.location.href); var text = encodeURIComponent('Check out this page!'); // 分享的文本 var twitterUrl = 'https://twitter.com/intent/tweet?url=' + url + '&text=' + text; window.open(twitterUrl, 'twitter-share-dialog', 'width=626,height=436'); return false; }); $('.instagram-share-btn').click(function() { var instagramUrl = 'https://www.instagram.com/'; window.open(instagramUrl, '_blank'); return false; }); $('.youtube-share-btn').click(function() { var youtubeUrl = 'https://www.youtube.com/'; window.open(youtubeUrl, '_blank'); return false; }); $('.telegram-share-btn').click(function() { var url = encodeURIComponent(window.location.href); var text = encodeURIComponent('Check out this page!'); // 分享的文本 var telegramUrl = 'https://t.me/share/url?url=' + url + '&text=' + text; window.open(telegramUrl, 'telegram-share-dialog', 'width=626,height=436'); return false; }); $('.linkedin-share-btn').click(function() { var url = encodeURIComponent(window.location.href); var title = encodeURIComponent(document.title); // 获取当前页面的标题 var linkedinUrl = 'https://www.linkedin.com/shareArticle?url=' + url + '&title=' + title; window.open(linkedinUrl, 'linkedin-share-dialog', 'width=626,height=436'); return false; }); })