如何在Twitter

时间:2017-09-20 19:07:39

标签: javascript html css twitter

我收到了一些帮助,并想出了如何将可点击和可共享的Twitter按钮放入我的Javascript中。

然而,现在当它链接生成的引用时,在我有unicode转义字符的地方我得到了 。

引号和连字符不会出现。我该如何解决这个问题?

以下是我的Javascript代码。

var currentQuote = '';
var quotes = [
'\u201CMeditation is to be aware of every thought and of every feeling, never to say it is right or wrong, but just to watch it and move with it. In that watching, you begin to understand the whole movement of thought and feeling. And out of this awareness comes silence\u201D. -  Jiddu Krishnamurti',
'\u201CHave you not noticed that love is silence? It may be while holding the hand of another, or looking lovingly at a child, or taking in the beauty of an evening. Love has no past or future, and so it is with this extraordinary state of silence.\u201D -  Jiddu Krishnamurti',
'\u201CA quiet mind is all you need. All else will happen rightly, once your mind is quiet. As the sun on rising makes the world active, so does self-awareness affect changes in the mind. In the light of calm and steady self-awareness, inner energies wake up and work miracles without any effort on your part.\u201D -   Nisargadatta Maharaj',
'\u201CLet silence take you to the core of life.\u201D  \u2013 Rumi',
'\u201CSilence is a true friend who never betrays.\u201D \u2013 Confucius',
'\u201CYou throw thorns, falling in my silence they become flowers.\u201D \u2013 Gautama Buddha',
'\u201CSilence is an empty space, space is the home of the awakened mind.\u201D \u2013 Gautama Buddha',
'\u201CCare about what other people think and you will always be their prisoner.\u201D \u2013 Laozi',
'\u201CNot thinking about anything is Zen. Once you know this, walking, sitting, or lying down, everything you do is Zen.\u201D \u2013 Bodhidharma',
'\u201CIf you use your mind to study reality, you won\u2019t understand either your mind or reality. If you study reality without using your mind, you\u2019ll understand both.\u201D \u2013 Bodhidharma',
'\u201CThe ultimate Truth is beyond words. Doctrines are words. They\u2019re not the way.\u201D \u2013 Bodhidharma',
'\u201CWhen we\u2019re deluded there\u2019s a world to escape. When we\u2019re aware, there\u2019s nothing to escape.\u201D \u2013 Bodhidharma',
'\u201CTrying to find buddha or enlightenment is like trying to grab space.\u201D \u2013 Bodhidharma',
'\u201CBe empty of worrying. Think of who created thought. Why do you stay in prison when the door is wide open? Move outside the tangle of fear-thinking. Live in silence. Flow down and down in always widening rings of being.\u201D  \u2013 Unknown',
'\u201CBeyond The Witness, there is the Infinite Intensity of Emptiness and Silence.\u201D \u2013 Sri Nisargadatta Maharaj'
];

function newQuote() {
  var randomNumber = Math.floor(Math.random() * (quotes.length));
  document.getElementById('quoteDisplay').innerHTML = quotes[randomNumber];


}

function tweet() {
  var quote = document.getElementById('quoteDisplay').innerHTML // Replace this with appopriate quote that you wanted.
  var text = quote;
  var tweet_url = "https://twitter.com/intent/tweet?text=" + text;
  window.open(tweet_url);
};
document.getElementById("tweetButton").addEventListener("click", tweet);

This is what shows up

它最初有这个,

var text = escape(quote);

但不会显示任何内容,所以我把

var text = quote; 

然而,现在我得到了 。

2 个答案:

答案 0 :(得分:0)

您可以在onclick中指定功能,以便像链接一样调用该功能



var currentQuote = '';
var quotes = [
  '\u201CMeditation is to be aware of every thought and of every feeling, never to say it is right or wrong, but just to watch it and move with it. In that watching, you begin to understand the whole movement of thought and feeling. And out of this awareness comes silence\u201D. -  Jiddu Krishnamurti',
  '\u201CHave you not noticed that love is silence? It may be while holding the hand of another, or looking lovingly at a child, or taking in the beauty of an evening. Love has no past or future, and so it is with this extraordinary state of silence.\u201D -  Jiddu Krishnamurti',
  '\u201CA quiet mind is all you need. All else will happen rightly, once your mind is quiet. As the sun on rising makes the world active, so does self-awareness affect changes in the mind. In the light of calm and steady self-awareness, inner energies wake up and work miracles without any effort on your part.\u201D -   Nisargadatta Maharaj',
  '\u201CLet silence take you to the core of life.\u201D  \u2013 Rumi',
  '\u201CSilence is a true friend who never betrays.\u201D \u2013 Confucius',
  '\u201CYou throw thorns, falling in my silence they become flowers.\u201D \u2013 Gautama Buddha',
  '\u201CSilence is an empty space, space is the home of the awakened mind.\u201D \u2013 Gautama Buddha',
  '\u201CCare about what other people think and you will always be their prisoner.\u201D \u2013 Laozi',
  '\u201CNot thinking about anything is Zen. Once you know this, walking, sitting, or lying down, everything you do is Zen.\u201D \u2013 Bodhidharma',
  '\u201CIf you use your mind to study reality, you won\u2019t understand either your mind or reality. If you study reality without using your mind, you\u2019ll understand both.\u201D \u2013 Bodhidharma',
  '\u201CThe ultimate Truth is beyond words. Doctrines are words. They\u2019re not the way.\u201D \u2013 Bodhidharma',
  '\u201CWhen we\u2019re deluded there\u2019s a world to escape. When we\u2019re aware, there\u2019s nothing to escape.\u201D \u2013 Bodhidharma',
  '\u201CTrying to find buddha or enlightenment is like trying to grab space.\u201D \u2013 Bodhidharma',
  '\u201CBe empty of worrying. Think of who created thought. Why do you stay in prison when the door is wide open? Move outside the tangle of fear-thinking. Live in silence. Flow down and down in always widening rings of being.\u201D  \u2013 Unknown',
  '\u201CBeyond The Witness, there is the Infinite Intensity of Emptiness and Silence.\u201D \u2013 Sri Nisargadatta Maharaj'
];

function newQuote() {
  var randomNumber = Math.floor(Math.random() * (quotes.length));
  document.getElementById('quoteDisplay').innerHTML = quotes[randomNumber];


}

function newFunction() {
  alert("Javascript Link");
}

body {
  font-family: 'PT Serif', sans-serif;
  margin: 0;
  <!-- the above allows use of older browsers #D13053 -->
}

h1 {
  color: white;
  font-size: 45px;
  <!-- margin-top: 100px;
  -->font-weight: normal;
  margin-bottom: 0;
}

h2 {
  color: white;
  font-size: 25px;
  margin-top: 0;
}

.bio {
  color: white;
  font-size: 14px;
}

.me {
  height: 165px;
  border-radius: 110%;
  border-style: solid;
  border-color: white;
  margin-top: 40px;
}

.about {
  width: 400px;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
}

.grey {
  height: 3px;
  background-color: white;
  border: none;
  width: 50px;
}

.about-container {
  background: url('inc.jpg') no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  height: 2000px;
}

h3 {
  text-align: center;
  font-size: 28px;
  font-weight: normal;
  margin-top: 100px;
  color: white;
}

h4 {
  text-align: center;
  font-size: 24px;
}

button {
  border-radius: 20px;
  background-color: #ffffff;
  font-size: 30px;
  font-family: PT Serif, cursive;
  padding: 0 20px;
  border: none;
  border-bottom: black solid 3px;
  margin-top: 85px;
  vertical-align: bottom;
}

.tweet-button {
  display: block;
  margin-left: auto;
  margin-right: auto;
  margin-top: 0px;
  margin-bottom: 30px;
  transition: all 0.5s;
  cursor: pointer;
  height: 80px;
}

.tweet-button span {
  cursor: pointer;
  display: inline-block;
  position: relative;
  transition: 0.5s;
}

.tweet-button:active {
  transform: translateY(5px);
}
&#13;
<html>

<head>

  <link rel="stylesheet" type="text/css" href="style.css">
  <link href="https://fonts.googleapis.com/css?family=PT+Serif:400,400i,700,700i" rel="stylesheet">


  <title>Your Core</title>
</head>

<body>

  <iframe style="display: none;" width="560" height="315" src="https://www.youtube.com/embed/H2JtoG97zhI?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>

  <div class="about-container">
    <div class="about">
      <img src="fib2.jpg" class="me" />


      <h1> Find the space, </h1>


      <h2>the space which is between thoughts...</h2>

      <hr class="grey" />



      <button onclick="newQuote()">Breathe and press here
			    </button>


      <h3>
        <div id="quoteDisplay">
          <!-- quotes here -->
        </div>
      </h3>




      <img id="tweetButton" class="tweet-button" src="http://orig01.deviantart.net/dac8/f/2013/023/b/c/twitter_button___logo_by_pixxiepaynee-d5sfq9u.png" onclick="newFunction();">

      <script src="javascript.js"></script>


</body>

</html>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

这是一种简单的方法,您可以通过推特按钮发布推文。

function tweet() {
  var quote = document.getElementById('quoteDisplay').innerHTML // Replace this with appopriate quote that you wanted.
  var text = escape(quote);
  var tweet_url = "https://twitter.com/intent/tweet?text=" + text;
  window.open(tweet_url);
};
document.getElementById("tweetButton").addEventListener("click", tweet);