Implement a Facebook Share Button Using a Single Line of Javascript

July 12, 2010

If you’ve messed with getting Facebook buttons on your site you know that there are a couple of ways > to do it, but most of them involve using one of their various APIs.

My issue is that I’ve been working on optimizing my site, so I didn’t want to invoke any external scripts at all. So I did a few minutes of research and came up with a way to be able to submit to Facebook–just like their share button–using a single line of Javascript:

screen-shot-2014-11-30-at-11.28.58-pm

Basically, you’re just sending two parameters (u for url, and t for title) to a single url: facebook.com/sharer.php. ::

supporting = loving

3,000+ posts over 25 years—security, AI, technology, meaning—all free, no ads, one person. If even one idea here saved you time, changed your thinking, or made you better at your craft, you got a mass of value for free.

A few bucks a month keeps this going. Pick an amount that feels right.