简体   繁体   English

在 asp.net 4.0 上显示 facebook 的类似按钮

[英]show like button of facebook on asp.net 4.0

I am trying to use below code in my asp.net but i am getting error.我正在尝试在我的 asp.net 中使用以下代码,但出现错误。

 <script type="text/javascript">
    window.fbAsyncInit = function () {
        FB.init({ appId: 'xxxxxxx', status: true, cookie: true,
            xfbml: true
        });
    };
    (function () {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        document.getElementById('<%= fb-root.ClientID %>').appendChild(e);
    } ());
</script>

i am getting error getElementById as it shows error that fb doesn't exist.我收到错误 getElementById 因为它显示 fb 不存在的错误。 i have a div with id as fb-root.我有一个 id 为 fb-root 的 div。

Is your <div> with ID fb-root has runat="server" ?您的 ID fb-root<div>是否有runat="server"

If not, ClientID won't work, just use getElementById('fb-root');如果没有, ClientID将不起作用,只需使用getElementById('fb-root');

If yes, try viewing source of the page to see what kind of ID you get for your script.如果是,请尝试查看页面的源代码以查看您为脚本获得的 ID 类型。 It's also helpful to check for null reference to avoid errors, like this:检查 null 参考以避免错误也很有帮助,如下所示:

var divFBRoot  = document.getElementById('fb-root');

if( String(divFBRoot) != 'undefined' )
{
   //do your things
}

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

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