2013-11-02 103 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