简体   繁体   中英

Asp.Net Facebook Like Button Error

I first create my App in Facebook and then I got the code from Facebook for like button. You can verify my code as;
I am using HTML5 Version;

<script>(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/all.js#xfbml=1&appId=123456789";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

My button Code is;

<div class="fb-like" data-href="http://www.google.com.pk" data-send="false" 
     data-layout="button_count" data-width="450" data-show-faces="true"></div>

But when I click on 'like button', a new window pop up and after a few seconds I get this error in;

 The webpage you are trying to viewing try to close the browser. Do you want to close the browser?

Then I press the F12 in IE10, and I saw the 'Error Console' for javascript, I got nothing.
I also tried in Chrome and FireFox and when I click on a button, the button disappears (in Firefox and Chrome).

What am I getting wrong?
Do I need an extra step in my Facebook App I-e developer.facebook.com

If you are giving data-href="http://www.google.com.pk" then it is wrong. You should provide a facebook page.

And change the class to 'fb-like-box' from 'fb-like'

The best solution is this.

You dont need use http:// on the Uri.

You can use the next method on a razor View:

@HttpContext.Current.Request.Url.AbsoluteUri.Replace("http://", "").

A complete example:

 <div id="fb-root"></div>
    <script>
(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/es_LA/sdk.js#xfbml=1&version=v2.8&appId=YOUAPPID";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
    <h1>Facebook Like Example</h1>
    @HttpContext.Current.Request.Url.AbsoluteUri.Replace("http://", "")


<div class="fb-like" data-href="@HttpContext.Current.Request.Url.AbsoluteUri.Replace("http://","")" data-layout="standard" data-action="like" data-size="small" data-show-faces="true" data-share="true"></div>

Note: On you facebook app you need use the full URL: http://iscangelmartinez.azurewebsites.net

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM