Custom Facebook Share and Twitter Tweet Buttons


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

This code actually opens up another tab (rather than a pop up) in IE6 & IE7 - but if you can live with that it seems to work well in all modern browsers. I'm open to any additions/revisions that anyone finds appropriate. Props to the URL above for providing the pop up function. I use PHP in this case to supply the URL to be shared - feel free to replace with a static url or whatever you need.


Copy this code and paste it in your HTML
  1. <script type="text/javascript">
  2. function popUp(URL) {
  3. day = new Date();
  4. id = day.getTime();
  5. eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=500,left = 710,top = 290');");
  6. }
  7. </script>
  8.  
  9. <?php
  10. $currentsite = "Enter your URL Here";
  11. $twitter_url = "http://twitter.com/share?url=" . $currentsite . "&text=I found this great site at " . $currentsite;
  12. $facebook_url = "http://www.facebook.com/sharer.php?u=" . $currentsite;
  13. ?>
  14.  
  15. <a href="javascript:popUp('<?php print urlencode($facebook_url); ?>')"><img src="images/facebook.gif" alt="facebook"/></a>
  16. <a href="javascript:popUp('<?php print urlencode($twitter_url); ?>')"><img src="images/twitter.gif" alt="twitter"/></a>

URL: http://javascript.internet.com/generators/popup-window.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.