QQ、新浪微博、微信、QQ空间分享
将网站分享到第三方,如下:
1.引入jquery
2.js插件,代码如下:
(function (global, doc, factoryFn) {var factory = factoryFn(global, doc);if (!(typeof (ChePC) === 'object')) {ChePC = {};}ChePC.sharePage = ChePC.sharePage || factory;window.define && define(function (require, exports, module) {return factory;});
})(this, document, function (window, document) {var sharePage = function (options) {var that = this,defaultOpts = {config: {shareUrl: window.location.href,shareTitle: document.title ? document.title : '',shareDescription: $("meta[name='description']").attr("content") ? $("meta[name='description']").attr("content") : '',shareImg: document.getElementsByTagName("img")[0] ? document.getElementsByTagName("img")[0].src : ''},wxConfig: {status: true,shareBtnName: '.shareBtn_wx'},wbConfig: {status: true,shareBtnName: '.shareBtn_wb'},qqkjConfig: {status: true,shareBtnName: '.shareBtn_qqkj'},qqConfig: {status: true,shareBtnName: '.shareBtn_qq'}};that.opts = $.extend(defaultOpts, options);that._init();that.bindFun();};sharePage.prototype = {wxSharePopMaskEl: $("#wxSharePopMask"),wxSharePopEl: $("#wxSharePop"),protocol: window.location.protocol,_init: function () {var that = this;if (that.opts.wxConfig.status) {$("body").on("click", that.opts.wxConfig.shareBtnName, function (event) {that.wxShare(event);});}if (that.opts.wbConfig.status && (!$(that.opts.wbConfig.shareBtnName).attr("href") || $(that.opts.wbConfig.shareBtnName).attr("href").indexOf("#") == 0)) {that.wbShare();}if (that.opts.qqkjConfig.status && (!$(that.opts.qqkjConfig.shareBtnName).attr("href") || $(that.opts.qqkjConfig.shareBtnName).attr("href").indexOf("#") == 0)) {that.qqkjShare();}if (that.opts.qqConfig.status && (!$(that.opts.qqConfig.shareBtnName).attr("href") || $(that.opts.qqConfig.shareBtnName).attr("href").indexOf("#") == 0)) {that.qqShare();}},wxShare: function (event) {//微信分享var that = this;that.methods.preventDefault(event);//绑定微信分享按钮点击事件if (that.wxSharePopEl.length == 0) {//添加弹窗样式that.methods.loadCssCode(that.cssCode);$("body").append(that.wxPopHtml);that.wxSharePopMaskEl = $("#wxSharePopMask");that.wxSharePopEl = $("#wxSharePop");}that.wxSharePopMaskEl.show();that.wxSharePopEl.show();},wbShare: function () {//微博分享var that = this,shareInfo = that.methods.getShareInfo(that.opts.wbConfig, that.opts)shareInfo.shareBtn.attr({"href": '//service.weibo.com/share/share.php?url=' + encodeURIComponent(shareInfo.url) + '&title=' + encodeURIComponent(shareInfo.title) + '&pic=' + encodeURIComponent(shareInfo.img) + '&appkey=2110961524&searchPic=false#_loginLayer_1487659638332',"target": "_blank"});},qqkjShare: function () {//https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=https://www.autohome.com.cn/news/201805/917771.html?pvareaid=2028130&title=【图】最高降6.5万 Jeep大切诺基售价下调_汽车之家&pics=&summary=//QQ空间分享var that = this,shareInfo = that.methods.getShareInfo(that.opts.qqkjConfig, that.opts),shareImg = shareInfo.img.indexOf("//") != 0 ? shareInfo.img : that.protocol + shareInfo.img;shareInfo.shareBtn.attr({"href": 'https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + encodeURIComponent(shareInfo.url) + '&title=' + encodeURIComponent(shareInfo.title) + '&summary=' + encodeURIComponent(shareInfo.description) + '&pics=' + encodeURIComponent(shareImg),"target": "_blank"});},qqShare: function () {//https://connect.qq.com/widget/shareqq/index.html?url=http://news.58che.com/news/2032726.html#0-sqq-1-34980-9737f6f9e09dfaf5d3fd14d775bfee85&title=英菲尼迪斯巴达勇士赛北京站 强者齐聚_英菲尼迪_58车&desc=&summary=&site=baidu//QQ空间分享var that = this,shareInfo = that.methods.getShareInfo(that.opts.qqConfig, that.opts);shareInfo.shareBtn.attr({"href": 'https://connect.qq.com/widget/shareqq/index.html?url=' + encodeURIComponent(shareInfo.url) + '&title=' + encodeURIComponent(shareInfo.title) + '&desc=&summary=' + encodeURIComponent(shareInfo.description) + '&site=58che',"target": "_blank"});},bindFun: function () {var that = this;$("body").on("click", "#wxSharePopMask,#wxSharePopCloseBtn", function () {$("#wxSharePopMask,#wxSharePop").hide();})},methods: {loadCssCode: function (code) {//动态添加样式表,以<style></style>方式添加到header 样式会立即生效var style = document.createElement('style');style.type = 'text/css';style.rel = 'stylesheet';try {//for Chrome Firefox Opera Safaristyle.appendChild(document.createTextNode(code));} catch (ex) {//for IEstyle.styleSheet.cssText = code;}var head = document.getElementsByTagName('head')[0];head.appendChild(style);},preventDefault: function (event) {//屏蔽默认行为var ev = event ? event : window.event;if (ev.preventDefault) {ev.preventDefault();} else {ev.returnValue = false;}},getShareInfo: function (btnConfig, opts) {//获取分享信息var shareBtn = $(btnConfig.shareBtnName),shareTitle = shareBtn.attr("data-shareTitle") ? shareBtn.attr("data-shareTitle") : opts.config.shareTitle,shareDescription = shareBtn.attr("data-shareDescription") ? shareBtn.attr("data-shareDescription") :opts.config.shareDescription,shareUrl = shareBtn.attr("data-shareUrl") ? shareBtn.attr("data-shareUrl") : opts.config.shareUrl,shareImg = shareBtn.attr("data-shareImg") ? shareBtn.attr("data-shareImg") : opts.config.shareImg;return {shareBtn: shareBtn,title: shareTitle,description: shareDescription,url: shareUrl,img: shareImg}}},cssCode: '.wxSharePopMask{display:none;position:fixed;top:0;left:0;z-index:110000;width:100%;height:100%;background:#000;overflow:hidden;opacity:0.3;filter:Alpha(opacity=30);}.wxSharePop{display:none;position:fixed;top:50%;left:50%;margin-left:-160px;margin-top:-160px;width:310px;height:320px;overflow:hidden;padding:20px 10px;background:#fff;border:1px solid #d8d8d8;z-index:110001;font-size:12px;font-family:"simsun";}.wxSharePopTitle{font-size:14px;height:16px;line-height:16px;}.wxSharePopCloseBtn{position:absolute;top:10px;right:10px;width:16px;height:16px;color:#999;font-size:20px;cursor:pointer;}.wxSharePopImg{display:block;width:220px;height:220px;margin:15px auto;}.wxSharePopDescript{line-height:26px;color:#666;}',wxPopHtml: '<div class="wxSharePopMask" id="wxSharePopMask"></div>\<div class="wxSharePop" id="wxSharePop">\<p class="wxSharePopTitle"><B>分享到微信朋友圈</B></p>\<a class="wxSharePopCloseBtn" id="wxSharePopCloseBtn">×</a>\<img src="//service.58che.com/qrcode/v1/qrcode/?info=' + window.location.href + '" class="wxSharePopImg">\<p class="wxSharePopDescript">\打开微信,点击底部的“发现”,<Br>\使用“扫一扫”即可将网页分享至朋友圈。\</p>\</div>'}return sharePage;
});
3.用法:
这种调用方式 分享的title自动获取的是页面tittle 描述是页面的description,分享地址是当前页面url 分享的图片是当前页面第一张图
var shareFun=new ChePC.sharePage();
如需定制这些分享信息
需用以下方式调用
var shareFun=new ChePC.sharePage({config:{shareUrl:"url地址", //选填 分享地址 默认为当前页面地址shareTitle:"分享标题", //选填 分享标题 默认为当前页面titleshareDescription:"分享描述",shareImg:"分享图片地址" //选填 分享图片 默认为当前页面第一张图片
}});
4.效果如下:
QQ、新浪微博、微信、QQ空间分享相关推荐
- 史上最具体Android集成QQ,微信,微博分享(不用第三方)持续更新中
QQ 下载sdk并执行demo 各种配置 IUiListener 分享图片 分享到QQ 分享到QZONE Sina微博 配置 选择集成sdk方式 分享图片 微信 朋友 朋友圈 如今项目中用个第三方登录 ...
- android qq分享自动弹出,史上最详细Android集成QQ,微信,微博分享(不要第三方)持续更新中...
QQ1 下载sdk并运行demo 2 各种配置 IUiListener 4 分享图片41 分享到QQ 41 分享到QZONE Sina微博配置 选择集成sdk方式 分享图片 现在项目中用个第三方登录, ...
- 史上最详细Android集成QQ,微信,微博分享(不用第三方)持续更新中
QQ 下载sdk并运行demo 各种配置 IUiListener 分享图片 分享到QQ 分享到QZONE Sina微博 配置 选择集成sdk方式 分享图片 微信 朋友 朋友圈 现在项目中用个第三方登录 ...
- qq、微信二次分享记录
1. 动态加载js脚本 页面在不同终端分享只要加载对应终端的sdk即可,所以采用动态脚本加载机制: var script = document.createElement('script'); scr ...
- 一键分享到微博、QQ、微信、QQ空间、豆瓣、人人网、开心网、百度贴吧~
**分享到微博.QQ.微信.空间等平台功能有很多插件可以用,例如:bShare. **1.bShare插件的使用** <dt>分享到:</dt> <dd> < ...
- 新浪微博、微信朋友圈、qq空间分享---qq空间分享
http://wiki.open.qq.com/wiki/mobile/SDK下载 一.清单文件配置 <!-- QZone分享必须加上下面两个activity --> <activi ...
- 新浪微博、微信朋友圈、qq空间分享---微信朋友圈
微信文档 需要导入keystore测试,或者打包出来测试 一.添加必要的权限支持: <uses-permission android:name="android.permission. ...
- 友盟的微信登录,QQ,新浪微博登录功能和分享功能
在这里我用的是友盟的登录,需要的请参考本文,直接撸代码, 提示:微信登录在一段时间内,只授权一次(只能调起一次登录页面),除非更换用户,才可以再调起登录页面. 0.本文需要导入jar包导完后鼠标右键A ...
- js实现QQ、微信、新浪微博分享功能
使用js实现QQ.微信.新浪微博分享功能. 微信分享需要手机扫描二维码,需要对url进行编码.在https协议下,扫描二维码时,浏览器打不开可能是没有安全证书导致的. js代码: 1 var shar ...
最新文章
- 华为将开源挑战 Oracle 的 AI 原生数据库 GaussDB
- E820-DTU模拟量无线数传电台:物联网工业现场无线数传应用
- 大数据、云计算、AI大牛都在这里了,就等你来捞干货
- POI--HSSFCellStyle类
- 学校邮箱注册IDEA、pycharm等全家桶(正式版就是香)
- 算法高级(24)-一致性哈希算法在分布式系统中的使用场景
- java类加载器分类_Java 类加载器的种类
- php用vscode开发,VSCode PHP开发
- 诸如北京现代 只有四个轮子和一电瓶由中国制造(转自新华网)
- pytorch项目源码理解
- 每日一句20191224
- HBase 官方文档中文版
- 微众银行“梦见”区块链
- MediaPipe基础(5)Pose(姿势)
- Python 2D游戏项目开发日记——像素世界(一)
- 深度学习中的特征(feature)指的是什么?
- java快速开发平台
- 手机浏览器唤起支付宝并打开指定页面
- 2022-解决Android studio 模拟机没有网络,app接口api运行不起来的问题
- 免费人人站CMS采集插件-人人站seo