更改分享按钮的内容

时间:2013-03-21 19:55:57

标签: javascript facebook plugins twitter share

所以我使用这个分享按钮插件用于推特和脸书。 但是,我不明白在按下按钮时我应该更改以获取我的URL和我的标题。请帮助。

HTML:

<a onclick="Share.facebook('URL','TITLE','IMG_PATH','DESC')"> {sharing is sexy}</a>
<a onclick="Share.twitter('URL','TITLE')"> {sharing is sexy}</a>

JS:

Share = {
    facebook: function(purl, ptitle, pimg, text) {
        url = 'http://www.facebook.com/sharer.php?s=100';
        url += '&p[title]=' + encodeURIComponent(ptitle);
        url += '&p[summary]=' + encodeURIComponent(text);
        url += '&p[url]=' + encodeURIComponent(purl);
        url += '&p[images][0]=' + encodeURIComponent(pimg);
        Share.popup(url);
    },
    twitter: function(purl, ptitle) {
        url = 'http://twitter.com/share?';
        url += 'text=' + encodeURIComponent(ptitle);
        url += '&url=' + encodeURIComponent(purl);
        url += '&counturl=' + encodeURIComponent(purl);
        Share.popup(url);
    },
    popup: function(url) {
        window.open(url,'','toolbar=0,status=0,width=626, height=436');
    }
};

该插件位于:http://www.webdesign.org/html-and-css/tutorials/how-to-create-a-share-button-for-your-site.22180.html

1 个答案:

答案 0 :(得分:0)

window.location.href会为您提供网页的网址,document.getElementsByTagName("title")会为您提供网页的标题元素。

这是回答你的问题,还是你想在按下按钮的时间设置这些值?

相关问题