Share Facebook and Twitter


/ Published in: JavaScript
Save to your folder(s)

Share current page on Facebook wall or Twitter


Copy this code and paste it in your HTML
  1. function share(type) {
  2. var url = window.location.href;
  3. var title = window.document.title;
  4. if(type == 'facebook') {
  5. window.open("http://www.facebook.com/share.php?src=bm&u=" + url + "&t=" + title);
  6. }else if(type == 'twitter') {
  7. window.open("http://twitter.com/home?status=" + url);
  8. }
  9. }
  10.  
  11.  
  12. <a href="#" onclick="share('facebook');">Facebook</a>
  13. <a href="#" onclick="share('twitter');">Twitter</a>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.