分享
function share(types) {
var title, imageUrl, url, description, keywords;
//获取文章标题
title = document.title;
//获取隐藏域中的图片地址
try {
imageUrl = document.getElementById("shareimg").innerHTML;
catch (e) {
imageUrl = "";
//假如图片为空获取网页中的第一张图片地址作为分享图
if (imageUrl == "") {
try {
imageUrl = document.images[0].src;
catch (e) {
imageUrl = "";
//获取当前网页url
url = document.location.href;
url = url.replace("html#", "html");
try {
//获取网页描述
description = document.querySelector('meta[name="description"]').getAttribute('content');
catch (e) {
description = "";
try {
//获取网页关键字
keywords = document.querySelector('meta[name="keywords"]').getAttribute('content');
catch (e) {
keywords = "";
//qq空间接口的传参
if (types == 'qzone') {
window.open('https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + url + '&title=' + title + '&pics=' + imageUrl + '&summary=' + description);
//新浪微博接口的传参
if (types == 'weibo') {
window.open('http://service.weibo.com/share/share.php?appkey=583395093&url=' + url + '&title=' + title + '&pic=' + imageUrl);
// //qq好友接口的传参
// if (types == 'qqim') {
// window.open('http://connect.qq.com/widget/shareqq/index.html?url=' + url + '&title=' + title + '&pics=' + imageUrl + '&summary=' + description + '&desc=' + keywords);
//
//生成二维码给微信扫描分享
if (types == 'weixin' || types == 'qqim') {
//在线二维码(服务器性能限制,仅测试使用,屏蔽非大陆ip访问)
// url = url.replaceAll("-", "%2D");
url=url.replace(/-/g, '%2D')
window.open('https://www.a-bm.cn/share.aspx?types=' + types + '&url=' + url);