分享一个js站点分享的代码

351 阅读1分钟

今天分享一个js分享站点的代码。

博客里边用的是百度分享。用起来很方便,就是不支持https。不过这个问题已经被解决。

点击这里去:解决百度分享不支持https

方便是方便,但毕竟不是自己写的,而且https的情况下,还需要引入文件。

自己也尝试下。不废话了,上代码。

<!DOCTYPE html>
<html>
<head>
<title>share</title>
<script src="https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div class="shareList">
    <ul class="clearfix">
        <button  onclick="wx();">微信朋友圈</button>
        <button  onclick="qq();">QQ好友</button>
        <button  onclick="kj();">QQ空间</button>
        <button  onclick="wb();">新浪微博</button>
        <button  onclick="qqwb();">腾讯微博</button>
        <button  onclick="db();">豆瓣网</button>
        <button  onclick="renren();">人人网</button>
    </ul>
</div>
<div class="shareClose"><a href="javascript:share();"></a></div>
 
<!-- 微信分享 start-->
<div class="bdsharebuttonbox" style="display:none;"><xx style="float: left; font-size: 12px;line-height:30px;"> </xx><a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信" id="wx_share"></a></div>
<script>
var href = 'https://guanchao.site';
window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdUrl":href,"bdPic":"","bdStyle":"1","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
<!-- 微信分享 end-->
 
</body>
</html>
<script type="text/javascript">
//分享到微信朋友圈
function wx(){
    var el = document.getElementById('wx_share');
    el.target = '_new';
    el.click();
}
 
//分享到QQ好友
function qq(){
    event.preventDefault();
    var _shareUrl = 'https://connect.qq.com/widget/shareqq/iframe_index.html?';
        _shareUrl += 'url=' + encodeURIComponent(location.href);   //分享的链接
        _shareUrl += '&title=' + encodeURIComponent(document.title);     //分享的标题
    window.open(_shareUrl,'_blank');
}
 
//分享到QQ空间
function kj() {
    var p = {
        url: location.href,
        showcount'1',/*是否显示分享总数,显示:'1',不显示:'0' */
        desc'',/*默认分享理由(可选)*/
        summary'',/*分享摘要(可选)*/
        title'',/*分享标题(可选)*/
        site'',/*分享来源 如:腾讯网(可选)*/
        // pics:'', /*分享图片的路径(可选)*/
        style'204',
        width98,
        height22
    };
    var s = [];
    for (var i in p) {
        s.push(i + '=' + encodeURIComponent(p[i] || ''));
    }
    window.open("http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?" + s.join('&'));
}
 
//分享到新浪微博
function wb() {
    var txtVal = ' ';        
    var url = window.location.href;
    window.open("http://v.t.sina.com.cn/share/share.php?appkey=4120396272&title=" + encodeURIComponent(txtVal)+"&url="+encodeURIComponent(url));
}
 
//分享到腾讯微博
function qqwb() {
    var content = " ";
    var url = location.href;
    var picurl = "";
    var shareqqstring='http://v.t.qq.com/share/share.php?title='+content+'&url='+url+'&pic='+picurl;
    window.open(shareqqstring,'newwindow','height=500,width=1000,top=200,left=500');
}
 
//分享到豆瓣
function db(){
    var title = ' ';
    var _shareUrl = 'http://shuo.douban.com/!service/share?';
        _shareUrl += 'href=' + encodeURIComponent(location.href);    //分享的链接
        _shareUrl += '&name=' + encodeURIComponent(title);    //分享的标题
        _shareUrl += '&image=' + encodeURIComponent('');    //分享的图片
        window.open(_shareUrl,'_blank');
}
 
//分享到人人网
function renren(){
    var title = ' ';
    var _shareUrl = 'http://share.renren.com/share/buttonshare.do?';
    _shareUrl += 'link=' + encodeURIComponent(location.href); //分享的链接
    _shareUrl += '&title=' + encodeURIComponent(title); //分享的标题
    window.open(_shareUrl,"'_blank','width='80',height='50'");
}
</script>

 

基本上就是这些了。

有好的建议,请在下方输入你的评论。

欢迎访问个人博客 guanchao.site

欢迎访问小程序:

在这里插入图片描述