简体   繁体   English

根据JavaScript变量发布内容

[英]Tweet something based on JavaScript variable

I have my Codepen which can be found here ( https://codepen.io/Mortiferr/pen/repRgX ) 我有我的Codepen,可以在这里找到( https://codepen.io/Mortiferr/pen/repRgX

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. 这是一种随机报价机,可从API生成随机报价。 I want to make it so that the user can tweet out the quote on the screen. 我想这样做,以便用户可以在屏幕上发布报价。 I have a variable called quote and author so I need to somehow use those to send out the tweet. 我有一个名为quoteauthor的变量,因此我需要以某种方式使用这些变量来发送tweet。

Thanks. 谢谢。

Here's how I did it: 这是我的操作方式:

$('.twitter').on('click', function() {
  makeTwitterPage('https://twitter.com/intent/tweet?text=' + encodeURIComponent('"' + quote + '" ' + author));
});
function makeTwitterPage(url){
  window.open(url, 'Share', 'width=700, height=500, toolbar=0, scrollbars=1 ,location=0 ,statusbar=0,menubar=0, resizable=1');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM