如何正确分享锚?

时间:2014-07-15 06:35:21

标签: jquery share facebook-social-plugins share-button

我打算为每个页面都有几个产品幻灯片的客户页面构建一个带锚点的共享按钮。但它不会起作用。
按钮/链接由jQuery生成以获取正确的ID。

链接将是:

var pathname = window.location.href;<br>
var facebookLink = 'https://www.facebook.com/sharer/sharer.php?u=' + pathname;<br>
var googleLink = 'https://plus.google.com/share?url=' + pathname;

对于我已经尝试过的锚点:

var anchor = '#' + anchor -> only the baseURL will be linked
var anchor = '%' + anchor -> the 404-Page will be linked
var anchor = '?a=' + anchor; -> only the baseURL will be linked

修改:要回答评论中的问题:链接应该共享页面并直接返回某个幻灯片。

编辑:完整的jQuery将是:

function executeClick(path,anchor) {
var pathname = window.location.href;
var facebookLink = 'https://www.facebook.com/sharer/sharer.php?u=' + pathname;
var twitterLink = 'https://twitter.com/home?status=' + pathname;
var googleLink = 'https://plus.google.com/share?url=' + pathname;
var whatsappLink = 'whatsapp://send?text=' + pathname;

var mailTo = '';
var subject = 'Recommend';
var mailLink = 'mailto:'+mailTo+'?subject='+subject+'&body='+pathname;

switch(path) {
    case 'facebook':
        path = facebookLink;
        break;
    case 'twitter':
        path = twitterLink;
        break;
    case 'google':
        path = googleLink;
        break;
    case 'whatsapp':
        path = whatsappLink;
        break;
    case 'recommend':
        path = mailLink;
        break;
}

if(path.indexOf('mailto') == -1) {
    if(anchor == 'none') {
        window.open(path, '_blank');
    }
    else {
        window.open(path + '#' + anchor, '_blank');
    }
}
else {
    if(anchor == 'none') {
        location.href = path;
    }
    else {
        location.href = path + '#' + anchor;
    }
}

0 个答案:

没有答案