2013-11-02 99 views
0

我正在尝试构建推文弹出链接。Twitter鸣叫链接不显示

我的HTML代码如下

<p class="col-xs-5 col-xs-offset-1" id="custom-tweet-button"> 
<a class="twitter-share-button shareButton twitter popup" href="http://twitter.com/share?text=My Custom text" data-text="My Custom text" data-count="none" data-url="https://www.google.com"> 
<img src="32399/images/social/tweet2.png" alt="" /> 
</a> 
</p> 

的JavaScript代码是

$('.popup').click(function(event) { 
    var width = 575, 
     height = 400, 
     left = ($(window).width() - width)/2, 
     top = ($(window).height() - height)/2, 
     url = this.href, 
     opts = 'status=1' + 
       ',width=' + width + 
       ',height=' + height + 
       ',top=' + top + 
       ',left=' + left; 

    window.open(url, 'twitter', opts); 

    return false; 
    }); 

问题是,当弹出发生,它只是显示的文本。 来自teh data-url的URL没有得到显示。我需要在推文链接中显示URL。

我创建了一个样本的jsfiddle

http://jsfiddle.net/yU9pP/1/

正如你可以看到,数据的URL不习惯于如何使用?

回答

1

您没有使用完整的twitter button,添加相应的JS代码段可以解决问题并激活data-url的用法。

<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> 

Demo

+0

嗯是的。但是,添加该twitter代码片段代码也会导致我的自定义图像消失。我可以通过在链接中的文字后添加来解决这个问题 –

1

我加在href以下和它的工作....是这样的方式来做到这一点?

http://twitter.com/share?text=My Text!&url=https://www.google.com