Sharing via Facebook SDK for Javascript

Welcome to Wisej Support.
Questions, suggestions and plain old bugs - are all welcome here!
Answered
0
0

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–>
<script>
window.fbAsyncInit = function () {
FB.init({
appId: ‘12345’,
autoLogAppEvents: true,
xfbml: true,
version: ‘v2.10’
});
FB.AppEvents.logPageView();
};

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

(where appID is a valid Facebook App ID)

 

Now I’m trying to implement the share function, as referenced here:¬†https://developers.facebook.com/docs/sharing/reference/share-dialog

FB.ui({
  method: 'share',
  mobile_iframe: true,
  href: 'https://developers.facebook.com/docs/',
}, 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: 'https://developers.facebook.com/docs/'," & _
 "}, 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?

thanks,

Andrew



 

Attachment
  • You must to post comments
Best Answer
0
0

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.

/Luca

  • Andrew
    Thanks, got it working.
  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Attachment
File Name Size
There are currently no files uploaded.
Maximum number of files 5, maximum file size 3.9MB.
Supported file formats: zip pdf gif jpg bmp png cs vb theme json