- 最近有加pc端的分享的需求,百度+自己写写了个整合的函数,以备后用
var imageUrl
var title, url, description, keywords;
function shareTo(types) {
title = document.title;
url = document.location.href;
description = document.querySelector('meta[name="description"]').getAttribute('content');
keywords = document.querySelector('meta[name="keywords"]').getAttribute('content');
if (types == 'qzone') {
window.open('https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + url + '&sharesource=qzone&title=' +
title + '&pics=' + imageUrl + '&summary=' + description);
}
if (types == 'sina') {
window.open('http://service.weibo.com/share/share.php?url=' + url + '&sharesource=weibo&title=' + title+' ' +description+ '&pic=' +
imageUrl + '&appkey=2706825840');
}
if (types == 'qq') {
window.open('http://connect.qq.com/widget/shareqq/index.html?url=' + url + '&sharesource=qzone&title=' + title +
'&pics=' + imageUrl + '&summary=' + description + '&desc=' + keywords);
}
if (types == 'wechat') {
jQuery('.qrcode').qrcode({
render: "canvas",
width: 100,
height: 100,
text: window.location.href
});
}
if (types=='douban'){
window.open('http://www.douban.com/recommend/?url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title));
}
if (types=='copy'){
var input = document.createElement('input');
document.body.appendChild(input);
input.setAttribute('value', window.location.href);
input.select();
if (document.execCommand('copy')) {
document.execCommand('copy');
layer.msg('<div class="jyalert"><div class="hd">' + '复制成功' + '</div></div>', {
area: 'auto',
title: '<i class="logo"></i>',
shade: [0.7, '#222e39'],
scrollbar: false,
closeBtn: false,
time: 2000,
btn: false,
}, function() {
});
}
document.body.removeChild(input);
}
}