Help tweeting text from a JavaScript Object


#1

I’m trying to get tweet functionality for my random quote generator here working, so that it autofills the tweet box with the quote text and author. The quote and author are objects within a javascript array, which gets pushed to the webpage using innerHTML everytime the button is pressed.

Is there a simple way to do this?


#2

You can create a new anchor element to place onto the page with text, url, and hashtag query parameters to pre-populate Tweet text.
https://dev.twitter.com/web/tweet-button/web-intent

You can also create a new Tweet button with a JavaScript factory function. A Tweet button is a web intent with styling recognized across the web.
https://dev.twitter.com/web/tweet-button/javascript-create


#3