Mortiferr Mortiferr - 1 year ago 69
Javascript Question

Tweet something based on JavaScript variable

I have my Codepen which can be found here (

I have a button like so:

<button onclick ="tweetIt()" class="twitter" href="#twitter"><i class="fa fa-twitter fa-lg"></i> Tweet Quote</button>

It is a random quote machine that generates a random quote from an API. I want to make it so that the user can tweet out the quote on the screen. I have a variable called
so I need to somehow use those to send out the tweet.


Answer Source

Thanks for all the help everyone -.-

Here's how I did it:

$('.twitter').on('click', function() {
  makeTwitterPage('' + encodeURIComponent('"' + quote + '" ' + author));
function makeTwitterPage(url){, 'Share', 'width=700, height=500, toolbar=0, scrollbars=1 ,location=0 ,statusbar=0,menubar=0, resizable=1');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download