网页分享到facebook


一、在网页头部加入如下代码:

    <meta property="og:url" class="fb_url" content="分享url" />
    <meta property="og:type"               content="website" />
    <meta property="og:title" class="fb_title" content="标题" />
    <meta property="og:description"        content="内容" />
    <meta property="og:image" content="图片"/>

以上属性值根据自身网站修改

二、HTML代码如下:

<a href="javascript:fbShare();" class="xq-facebook"><i class="share-icon-facebook"></i> <span>facebook</span></a>

三、JavaScript代码如下:

function fbShare(contentId) {

        u = document.getElementsByClassName("fb_url")[0].content;

        t = document.getElementsByClassName("fb_title")[0].content;

        window.open("http://www.facebook.com/sharer.php?u="+ encodeURIComponent(u) + "&t="+ encodeURIComponent(t), "sharer","toolbar=0,status=0,width=626,height=436");
        

    }

 


作者:dreams7433,发布于:2019/03/15
原文:https://www.cnblogs.com/phperlinxinlan/p/10529012.html