Random Quote Machine - updating twitter text

Hello all,

I’m having trouble getting the Tweet button in my quote generator to behave correctly.

I know this has been asked plenty of times before, but reading through some of the existing posts and trying things that were suggested there hasn’t fixed anything so far. Unsure what I’m doing wrong at this point!


The first time it loads, when I click the tweet button, the tweet populates with the correct quote. However, if I generate a new quote and then click tweet again, the text hasn’t updated to the new quote. Can anybody give me a clue as to what is wrong with my code?
(Also it’s including the codepen URL in my tweet (which it doesn’t do when I run it locally), but I assume that is just a codepen thing)

From doing a bit of digging, I’ve understood that I may need to create a new Tweet button each time I generate a new quote (so when clicking the new quote button), but I’m not sure how to go about this. I’ve looked into using the replacing my link tags with the createShareButton method and putting that in my getNewQuote() function and that didn’t seem to play ball either! The console in Chrome just keeps giving me error messages anytime I deviate from the code you see in the codepen above :

Any pointers will be gratefully received :slight_smile:

Yes if you use the widget you’ll have to recreate the button every time you roll a quote. There’s an easier way to do it with tweet web intent.

Check this thread and my answer.


I think I was somehow trying to combine the two. My understanding was I needed the widgets code in there before I could use the Web Intents. That seems to have solved it though, so thanks very much :smiley:

I guess that’ll teach me to read documentation properly next time :stuck_out_tongue: