Sharing via Facebook SDK for Javascript


Facebook is deprecating sharer.php (and sharer.php only allows 1 parameter in the shared URL) so I am trying to get the Facebook SDK for Javascript to work with WiseJ.


The initialization seems straightforward enough, an entry under Default.html, under the <body> tag

<!– JS for Facebook SDK for Javascript–>
window.fbAsyncInit = function () {
appId: ‘12345’,
autoLogAppEvents: true,
xfbml: true,
version: ‘v2.10’

(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) { return; }
js = d.createElement(s); = id;
js.src = “//”;
fjs.parentNode.insertBefore(js, fjs);
}(document, ‘script’, ‘facebook-jssdk’));

(where appID is a valid Facebook App ID)


Now I’m trying to implement the share function, as referenced here:

  method: 'share',
  mobile_iframe: true,
  href: '',
}, function(response){});

This seems to be jQuery which I guess I am badly putting into my WiseJ MenuItem , as HTML (calling the function via the "onclick" method):

 Dim strFacebookHTML As String = "<a style='color:inherit;text-decoration:inherit' href='#' " & _
 "onclick='" & _
 "FB.ui({" & _
 "method: 'share'," & _
 "mobile_iframe: true," & _
 "href: ''," & _
 "}, function(response){});'" & _
 "" & _
 ">Share on FB</a>"

 Me.mnuShareFacebook.Text = strFacebookHTML
 Me.mnuShareFacebook.AllowHtml = True

In Chrome, clicking the MenuItem results in console error:

Unexpected token: }

I'm am fairly sure the problem is a syntax error, because I don't write enough Javascript. I'll keep plugging away at it, but if you see something I don't, could you point out my error?




  • You must to post comments
Best Answer

I  wouldn’t put the code in the href. You should have js file with your FB code added to Default.html and use the functions by name:

<a href=”#” onclick=”MyFB.share(…)”></a>

Or something like that. It makes it a lot easier to deal with the js syntax and with testing since you can call those functions directly.


  • Andrew Niese
    Thanks, got it working.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.