Click tweet button after changing data-text

92 views Asked by At

I'm trying to change the data-text on twitter share button with the tutorial in here: DEMO

But, is there any way to automatically click the "new" tweet button after changing the data-text? cause it has to clicked manually to show the share window

1

There are 1 answers

0
James Hibbard On BEST ANSWER

The Tweet button is in an iframe on another domain, so you won't be able to access it. I also couldn't find any documentation about how to open the window programatically, so here's my hacky solution: just open a popup to https://twitter.com/intent/tweet, passing it the necessary parameters in the query string. No need for a tweet button.

<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'
  )
});

This should work as desired. Demo.

Popup function from the mighty PPK: http://www.quirksmode.org/js/popup.html