網頁分享到facebook

1、在網頁頭部加入以下代碼:javascript

    <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="圖片"/>

以上屬性值根據自身網站修改php

2、HTML代碼以下:java

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

3、JavaScript代碼以下:web

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");
        

    }
相關文章
相關標籤/搜索