One of the most trivial implementations to sharing is sharing to Facebook. To my big surprise, I found out that Windows 8 has no built in Share to Facebook option. The People app has Sharing capabilities, but it only lets you post to your profile. What about sharing to in a private message? What about posting to a group? In my personal experience these are far more common use cases.

I’ve been playing around with the idea of creating this Share to Facebook thing myself, but I always kept hoping that someday they’ll just add it. The official Facebook app has a Share target, but it is just as useless as the People app share target.

So I gave up, I created my own Facebook share target. I’m just putting it here in case anyone else feels the same as I do about the built in Facebook sharing functionality. I’m not going to submit it to the store because I think it’s a stupid app. I really hope Microsoft or Facebook will add this soon and this post will be obsolete.

Here it is in action:

The code is basically just this:

(function(){'use strict';varapp=WinJS.Application;varshare;varfbShareUrlTemplate='https://www.facebook.com/sharer/sharer.php?u=';app.onready=function(args){theWebView.addEventListener(MSWebViewNavigationStarting,navigationStarting);};app.onactivated=function(args){if(args.detail.kind===Windows.ApplicationModel.Activation.ActivationKind.shareTarget){share=args.detail.shareOperation;if(share.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.uri)){share.data.getUriAsync().then(function(uri){if(uri!=null){varurlToNavigate=fbShareUrlTemplate+uri.absoluteUri;theWebView.navigate(urlToNavigate);}});}}};functionnavigationStarting(args){varurl=args.uri;if(url.substr(0,fbShareUrlTemplate.length)!==fbShareUrlTemplate){// if the url doesn't start with fbShareUrlTemplateargs.preventDefault();share.reportCompleted();}}app.start();})();

A couple of things to note:

It uses Facebook’s deprecated sharer.php.

It can only share urls, like from IE.

It is poorly written and tested.

Yes, I am lazy. But it’s serves me well, and I’m happy with it. And it just proves how simple it is to implement, so Microsoft \ Facebook – Please do!

This blog has no integrated comments section, but please share your feedback on Twitter or GitHub issues: