【问题标题】:Click tweet button after changing data-text更改数据文本后单击推文按钮
【发布时间】:2015-06-09 16:55:19
【问题描述】:

我正在尝试使用此处的教程更改 twitter 分享按钮上的数据文本:DEMO

但是,有没有办法在更改数据文本后自动单击“新”推文按钮?因为它必须手动点击才能显示共享窗口

【问题讨论】:

    标签: javascript jquery twitter


    【解决方案1】:

    Tweet 按钮位于另一个域的 iframe 中,因此您将无法访问它。我也找不到任何关于如何以编程方式打开窗口的文档,所以这是我的 hacky 解决方案:只需打开一个弹出窗口https://twitter.com/intent/tweet,并在查询字符串中传递必要的参数。无需推文按钮。

    <label for="tweetText">Tweet this:</label>            
    <input type="text" name="tweetText" id="tweetText" />
    <input type="button" value="Tweet" id="tweetSubmit" />
    
    function popitup(url) {
      newwindow=window.open(url,'name','height=850,width=730');
      if (window.focus) {newwindow.focus()}
      return false;
    }
    
    $('#tweetSubmit').on('click', function() {
      var text = $("#tweetText").val();
      popitup(
        "https://twitter.com/intent/tweet?text=" + text + 
        "&url=" + 'http://test.com'
      )
    });
    

    这应该可以正常工作。 Demo.

    强大的 PPK 的弹出功能:http://www.quirksmode.org/js/popup.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-29
      • 2022-12-04
      • 1970-01-01
      • 2018-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      相关资源
      最近更新 更多