Skip to content

Instantly share code, notes, and snippets.

@inerba
Last active February 23, 2018 11:51
Show Gist options
  • Save inerba/080c89529012b82afe55970afbf05dc8 to your computer and use it in GitHub Desktop.
Save inerba/080c89529012b82afe55970afbf05dc8 to your computer and use it in GitHub Desktop.
Social Share script & links

Script

;(function($){
  
  /**
   * jQuery function to prevent default anchor event and take the href * and the title to make a share popup
   *
   * @param  {[object]} e           [Mouse event]
   * @param  {[integer]} intWidth   [Popup width defalut 500]
   * @param  {[integer]} intHeight  [Popup height defalut 400]
   * @param  {[boolean]} blnResize  [Is popup resizeabel default true]
   */
  $.fn.sharePopup = function (e, intWidth, intHeight, blnResize) {
    
    // Prevent default anchor event
    e.preventDefault();
    
    // Set values for window
    intWidth = intWidth || '500';
    intHeight = intHeight || '400';
    strResize = (blnResize ? 'yes' : 'no');

    // Set title and open popup with focus on it
    var strTitle = ((typeof this.attr('title') !== 'undefined') ? this.attr('title') : 'Social Share'),
        strParam = 'width=' + intWidth + ',height=' + intHeight + ',resizable=' + strResize,            
        objWindow = window.open(this.attr('href'), strTitle, strParam).focus();
  }
  
  /* ================================================== */
  
  $(document).ready(function ($) {
    $('.share-popup').on("click", function(e) {
      $(this).sharePopup(e);
    });
  });
    
}(jQuery));

Example

 <a class="facebook share-popup" href="https://www.facebook.com/sharer.php?u=https://site.com" title="Facebook share" target="_blank">Facebook</a>

Facebook

Facebook has two methods of sharing. The "Sharer" link is simple but the preferred Facebook way is using the Share Dialog. This method does require an app id but offers more flexibility.

Sharer:

https://www.facebook.com/sharer.php?u={url}

Share Dialog:

https://www.facebook.com/dialog/share?app_id={app_id}&display=page&href={url}&redirect_uri={redirect_url}

Twitter

https://twitter.com/intent/tweet?url={url}&text={title}&via={via}&hashtags={hashtags}

Google+

https://plus.google.com/share?url={url}

Pinterest

https://pinterest.com/pin/create/bookmarklet/?media={img}&url={url}&is_video={is_video}&description={title}

LinkedIn

https://www.linkedin.com/shareArticle?url={url}&title={title}

Buffer

https://buffer.com/add?text={title}&url={url}

Digg

http://digg.com/submit?url={url}&title={title}

Tumblr

https://www.tumblr.com/widgets/share/tool?canonicalUrl={url}&title={title}&caption={desc}

Reddit

https://reddit.com/submit?url={url}&title={title}

StumbleUpon

http://www.stumbleupon.com/submit?url={url}&title={title}

Delicious

https://delicious.com/save?v=5&provider={provider}&noui&jump=close&url={url}&title={title}

Blogger

https://www.blogger.com/blog-this.g?u={url}&n={title}&t={desc}

LiveJournal

http://www.livejournal.com/update.bml?subject={title}&event={url}

Yahoo

http://compose.mail.yahoo.com/?body={url}

NewsVine

http://www.newsvine.com/_tools/seed&save?u={url}

EverNote

http://www.evernote.com/clip.action?url={url}

GetPocket

https://getpocket.com/save?url={url}

FlipBoard

https://share.flipboard.com/bookmarklet/popout?v=2&title={title}&url={url}

InstaPaper

http://www.instapaper.com/edit?url={url}&title={title}&description={desc}

Line.me

https://lineit.line.me/share/ui?url={url}

Skype

https://web.skype.com/share?url={url}

Viber

viber://forward?text={url}

WhatsApp

whatsapp://send?text={url}

Telegram.me

https://telegram.me/share/url?url={url}&text={title}

VK

http://vk.com/share.php?url={url}

OKru

https://connect.ok.ru/dk?st.cmd=WidgetSharePreview&st.shareUrl={url}&title={title}

Douban

http://www.douban.com/recommend/?url={url}&title={title}

Baidu

http://cang.baidu.com/do/add?it={title}&iu={url}

QZone

http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url={url}

Xing

https://www.xing.com/app/user?op=share&url={url}

RenRen

http://widget.renren.com/dialog/share?resourceUrl={url}&srcUrl={url}&title={title}

Weibo

http://service.weibo.com/share/share.php?url={url}&appkey=&title={text}&pic=&ralateUid=
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment