2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > 一键分享到QQ空间 QQ好友 新浪微博 微信代码

一键分享到QQ空间 QQ好友 新浪微博 微信代码

时间:2019-06-23 20:07:40

相关推荐

一键分享到QQ空间 QQ好友 新浪微博 微信代码

通过qq空间qq聊天新浪微博和微信二维码分享平台提供的接口实现把网页中对应的图片、标题、描述的信息参数用javascript获取后传进接口中,实现一键分享

使用到的接口:

1.分享到QQ空间接口:https://sns./cgi-bin/qzshare/cgi_qzshare_onekey?url=你的网址&sharesource=qzone&title=你的分享标题&pics=你的分享图片&summary=你的分享描述信息

2.分享给QQ好友接口:/widget/shareqq/index.html?url=你的分享网址&sharesource=qzone&title=你的分享标题&pics=你的分享图片地址&summary=你的分享描述&desc=你的分享简述

3.分享到新浪微博接口:/share/share.php?url=你的分享网址&sharesource=weibo&title=你的分享标题&pic=你的分享图片&appkey=你的key,需要在新浪微博开放平台中申请

一键分享代码参考如下:

html
<divclass="fl">分享到:</div><divonclick="shareTo('qzone')"><imgsrc="/static/images/qqzoneshare.png"width="30"></div><divonclick="shareTo('qq')"><imgsrc="/static/images/qqshare.png"width="32"></div><divonclick="shareTo('sina')"><imgsrc="/static/images/sinaweiboshare.png"width="36"></div><divonclick="shareTo('wechat')"><imgsrc="/static/images/wechatshare.png"width="32"></div>

js
functionshareTo(stype){varftit='';varflink='';varlk='';//获取文章标题ftit=$('.pctitle').text();//获取网页中内容的第一张图片flink=$('.pcdetailsimg').eq(0).attr('src');if(typeofflink=='undefined'){flink='';}//当内容中没有图片时,设置分享图片为网站logoif(flink==''){lk='http://'+window.location.host+'/static/images/logo.png';}//如果是上传的图片则进行绝对路径拼接if(flink.indexOf('/uploads/')!=-1){lk='http://'+window.location.host+flink;}//百度编辑器自带图片获取if(flink.indexOf('ueditor')!=-1){lk=flink;}//qq空间接口的传参if(stype=='qzone'){window.open('https://sns./cgi-bin/qzshare/cgi_qzshare_onekey?url='+document.location.href+'?sharesource=qzone&title='+ftit+'&pics='+lk+'&summary='+document.querySelector('meta[name="description"]').getAttribute('content'));}//新浪微博接口的传参if(stype=='sina'){window.open('/share/share.php?url='+document.location.href+'?sharesource=weibo&title='+ftit+'&pic='+lk+'&appkey=2706825840');}//qq好友接口的传参if(stype=='qq'){window.open('/widget/shareqq/index.html?url='+document.location.href+'?sharesource=qzone&title='+ftit+'&pics='+lk+'&summary='+document.querySelector('meta[name="description"]').getAttribute('content')+'&desc=php自学网,一个web开发交流的网站');}//生成二维码给微信扫描分享if(stype=='wechat'){window.open('inc/qrcode_img.php?url=/article-1.html');}}

原作地址:/article-309.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。