網頁分享到微信、微博、QQ等

首先要說明的是,pc端微信分享只能通過二維碼來分享。
部分代碼如下:

 //分享到新浪微博
    function shareToSinaWB(event){
        event.preventDefault();
        var _shareUrl = 'http://v.t.sina.com.cn/share/share.php?&appkey=895033136';     //真實的appkey,必選參數
        _shareUrl += '&url='+ encodeURIComponent(_url||document.location);     //參數url設置分享的內容鏈接|默認當前頁location,可選參數
        _shareUrl += '&title=' + encodeURIComponent(_title||document.title);    //參數title設置分享的標題|默認當前頁標題,可選參數
        _shareUrl += '&source=' + encodeURIComponent(_source||'');
        _shareUrl += '&sourceUrl=' + encodeURIComponent(_sourceUrl||'');
        _shareUrl += '&content=' + 'utf-8';   //參數content設置頁面編碼gb2312|utf-8,可選參數
        _shareUrl += '&pic=' + encodeURIComponent(_pic||'');  //參數pic設置圖片鏈接|默認爲空,可選參數
        window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',top='+_top+',left='+_left+',toolbar=no,menubar=no,scrollbars=no, resizable=1,location=no,status=0');
    }

    //分享到QQ空間
    function shareToQzone(event){
        event.preventDefault();

        var _shareUrl = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?';
        _shareUrl += 'url=' + encodeURIComponent(_url||document.location);   //參數url設置分享的內容鏈接|默認當前頁location
        _shareUrl += '&showcount=' + _showcount||0;      //參數showcount是否顯示分享總數,顯示:'1',不顯示:'0',默認不顯示
        _shareUrl += '&desc=' + encodeURIComponent(_desc||'分享的描述');    //參數desc設置分享的描述,可選參數
        _shareUrl += '&summary=' + encodeURIComponent(_summary||'分享摘要');    //參數summary設置分享摘要,可選參數
        _shareUrl += '&title=' + encodeURIComponent(_title||document.title);    //參數title設置分享標題,可選參數
        _shareUrl += '&site=' + encodeURIComponent(_site||'');   //參數site設置分享來源,可選參數
        _shareUrl += '&pics=' + encodeURIComponent(_pic||'');   //參數pics設置分享圖片的路徑,多張圖片以"|"隔開,可選參數
        window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',top='+_top+',left='+_left+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
    }

    //分享到百度貼吧
    function shareToTieba(event){
        event.preventDefault();

        var _shareUrl = 'http://tieba.baidu.com/f/commit/share/openShareApi?';
        _shareUrl += 'title=' + encodeURIComponent(_title||document.title);  //分享的標題
        _shareUrl += '&url=' + encodeURIComponent(_url||document.location);  //分享的鏈接
        _shareUrl += '&pic=' + encodeURIComponent(_pic||'');    //分享的圖片
        window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
    }

    //分享到豆瓣
    function shareToDouban(event){
        event.preventDefault();

        var _shareUrl = 'http://shuo.douban.com/!service/share?';
        _shareUrl += 'href=' + encodeURIComponent(_url||location.href);    //分享的鏈接
        _shareUrl += '&name=' + encodeURIComponent(_title||document.title);    //分享的標題
        _shareUrl += '&image=' + encodeURIComponent(_pic||'');    //分享的圖片
        window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
    }
    //分享到騰訊微博
    function shareToQQwb(event){
        event.preventDefault();

        var _shareUrl = 'http://v.t.qq.com/share/share.php?';
        _shareUrl += 'title=' + encodeURIComponent(_title||document.title);    //分享的標題
        _shareUrl += '&url=' + encodeURIComponent(_url||location.href);    //分享的鏈接
        _shareUrl += '&appkey=5bd32d6f1dff4725ba40338b233ff155';    //在騰迅微博平臺創建應用獲取微博AppKey
        _shareUrl += '&site=' + encodeURIComponent(_site||'');   //分享來源
        _shareUrl += '&pic=' + encodeURIComponent(_pic||'');    //分享的圖片,如果是多張圖片,則定義var _pic='圖片url1|圖片url2|圖片url3....'
        window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
    }
    //分享到人人網
    function shareToRenren(event){
        event.preventDefault();

        var _shareUrl = 'http://share.renren.com/share/buttonshare.do?';
        _shareUrl += 'link=' + encodeURIComponent(_url||location.href);   //分享的鏈接
        _shareUrl += '&title=' + encodeURIComponent(_title||document.title);     //分享的標題
        window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
    }

    //分享到開心網
    function shareToKaixin(event){
        event.preventDefault();

        var _shareUrl = 'http://www.kaixin001.com/rest/records.php?';
        _shareUrl += 'url=' + encodeURIComponent(_url||location.href);    //分享的鏈接
        _shareUrl += '&content=' + encodeURIComponent('分享的文字');    //需要分享的文字,當文字爲空時,自動抓取分享網址的title
        _shareUrl += '&pic=' + encodeURIComponent(_pic||'');     //分享的圖片,多個使用半角逗號分隔
        _shareUrl += '&showcount=0';    //是否顯示分享數,顯示:'1',不顯示:'0'
        _shareUrl += '&style=11';      //顯示的樣式,必選參數
        _shareUrl += '&aid=' + encodeURIComponent(_site||'');    //顯示分享來源
        window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
    }

    function shareToKaixin2(event){
        event.preventDefault();

        var _shareUrl = 'http://www.kaixin001.com/repaste/share.php?';
        _shareUrl += 'rtitle=' + encodeURIComponent(_title||document.title);   //分享的標題
        window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
    }

    //分享到facebook
    function shareToFacebook(event){
        event.preventDefault();

        var _shareUrl = 'http://www.facebook.com/sharer/sharer.php?';
        _shareUrl += 'u=' + encodeURIComponent(_url||location.href);    //分享的鏈接
        _shareUrl += '&t=' + encodeURIComponent(_title||document.title);    //分享的標題
        window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
    }
    //分享到facebook
    function shareToFacebook(event){
        event.preventDefault();

        var _shareUrl = 'http://www.facebook.com/sharer/sharer.php?';
        _shareUrl += 'u=' + encodeURIComponent(_url||location.href);    //分享的鏈接
        _shareUrl += '&t=' + encodeURIComponent(_title||document.title);    //分享的標題
        window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
    }

    //分享到Twitter
    function shareToTwitter(event){
        event.preventDefault();

        var _shareUrl = 'http://twitter.com/intent/tweet?';
        _shareUrl += 'url=' + encodeURIComponent(_url||location.href);    //分享的鏈接
        _shareUrl += '&text=' + encodeURIComponent(_title||document.title);    //分享的標題
        window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
    }

顯示地址:http://sabrinatian.github.io/webpage-sharing/share.html
ps:因爲沒加二維碼的圖片,因此代碼顯示網頁中的微信分享下沒有圖片
完整代碼下載地址:https://github.com/SabrinaTian/webpage-sharing/tree/gh-pages

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章