Twitter Tweet Button does not count

后端 未结 7 1047
不思量自难忘°
不思量自难忘° 2021-02-05 07:45

I am using the official Tweet Button from Twitter to allow users to share my site.

The button itself is working just fine, however the counter doesn\'t work and stays at

相关标签:
7条回答
  • 2021-02-05 08:27

    I had luck switching from the URL parameter method to the data- attributes method.

    function twtrButton(url, text, configs){
        // Create a link
        var params = {
            rel: 'canonical',
            'data-count': 'horizontal',
            href: 'http://twitter.com/share/'
        };
        if (url) {
            params['data-url'] = url;
            params['data-counturl'] = url;
        }
        if (text) {
            if(text.length > 90){
                text = text.substring(0, 90);
                text += '...';
            }
            params['data-text'] = text;
        }
        if (configs) {
            if (configs.via) {
                params['data-via'] = configs.via;
            }
            if (configs.related) {
                params['data-related'] = configs.related;
            }
        }
        var link = $('<a>', params).addClass('twitter-share-button');
        return link;
    }
    

    This snippet assumes jQuery 1.5 or greater.

    0 讨论(0)
提交回复
热议问题