推特推文链接未显示

Twitter tweet link not displaying

本文关键字:显示 链接 文链接      更新时间:2023-09-26

我正在尝试建立一个推文弹出链接。

我的 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;
  });

问题是当弹出窗口发生时,它只显示文本。未显示来自数据网址的网址。我也需要在推文链接中显示 URL。

我创建了一个示例 jsfiddle

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

如您所见,数据网址没有被使用

如何使用。?

您没有使用完整的 Twitter 按钮,添加相应的 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>

演示

我在 href 中添加了以下内容,它起作用了....这是这样做的方法吗?

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