简体   繁体   English

Asp.Net Facebook赞按钮错误

[英]Asp.Net Facebook Like Button Error

I first create my App in Facebook and then I got the code from Facebook for like button. 我先在Facebook中创建我的应用程序,然后从Facebook获得类似按钮的代码。 You can verify my code as; 您可以将我的代码验证为:
I am using HTML5 Version; 我正在使用HTML5版本;

<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. 然后按IE10中的F12,然后看到javascript的“错误控制台”,但我什么也没得到。
I also tried in Chrome and FireFox and when I click on a button, the button disappears (in Firefox and Chrome). 我也在Chrome和FireFox中尝试过,当我单击一个按钮时,该按钮消失了(在Firefox和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. 如果您要提供data-href =“ http://www.google.com.pk”,那是错误的。 You should provide a facebook page. 您应该提供一个Facebook页面。

And change the class to 'fb-like-box' from 'fb-like' 并将类从“ fb-like”更改为“ fb-like-box”

The best solution is this. 最好的解决方案是这样。

You dont need use http:// on the Uri. 您不需要在Uri上使用http://。

You can use the next method on a razor View: 您可以在剃刀视图上使用下一个方法:

@HttpContext.Current.Request.Url.AbsoluteUri.Replace("http://", ""). @ 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 注意:在您的Facebook应用上,您需要使用完整的URL: http : //iscangelmartinez.azurewebsites.net

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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