Share on facebook - chrome extension

Posted by Anuraj on Wednesday, June 25, 2014

CodeProject HTML5 Javascript

Long back I wrote a post about how to create a chrome extension. This post is about creating an extension which will help you to share current page URL on facebook. You can follow the same steps in the previous post except few changes in the background.js file. And facebook uses a URL like this to accept URL - http://www.facebook.com/sharer.php?u=[URL to share].

chrome.contextMenus.create({
    "title": "Share this URL on Facebook",
    "contexts": ["page", "link"],
    "onclick": function() {
		chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
			Popup(tabs[0].url);
		});
    }
});

function Popup(url) {
  chrome.windows.create({'url': 'http://www.facebook.com/sharer.php?u=' + url, 'type': 'popup'}, function(window) {});
}

And here is the screenshot of the extension running on my chrome browser.

Share on facebook from chrome extension

You can find the source code on GitHub - https://github.com/anuraj/ShareOnFb

Happy Programming :)



Did you like this article? Share it with your friends

Facebook Twitter Google+ LinkedIn Reddit StumbleUpon



MVP
Subscribe


Copyright © 2017 - Anuraj P. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Hosted with ❤ by GitHub