Hello I have trouble rotating the message on the tweet button..
I tried to insert this script:
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://domain.com" data-text="message 1.">Tweet</a>
<script language="JavaScript">
<!--
var r_text = new Array ();
r_text[0] = "Message 1";
r_text[1] = "Message 2";
r_text[2] = "Message 3";
r_text[3] = "Message 4";
r_text[4] = "Message 5";
r_text[5] = "Message 6";
r_text[6] = "Message 7";
var i = Math.floor(7*Math.random())
document.write(r_text[i]);
//-->
</script>
I inserted this script in the data-text="" but it didn't work.
var r_text = new Array ();
r_text[0] = "Message 1";
r_text[1] = "Message 2";
r_text[2] = "Message 3";
r_text[3] = "Message 4";
r_text[4] = "Message 5";
r_text[5] = "Message 6";
r_text[6] = "Message 7";
var title_tag = document.getElementsByTagName("title");
title_tag[0].innerText = r_text[Math.floor(r_text.length*Math.random())];
EDITED: Now changes the text within the <title>
tag, instead of the <a>
's data-text
attribute.
So you want something like this?
<a href="https://twitter.com/share" id="tweet-button" class="twitter-share-button" data-url="http://domain.com" data-text="message 1.">Tweet</a>
<script language="text/javascript">
var r_text = [
"Message 1",
"Message 2",
"Message 3",
"Message 4",
"Message 5",
"Message 6",
"Message 7"
];
var tweet_button = document.getElementById('tweet-button');
setInterval(function() {
tweet_button.innerHTML = r_text[Math.floor(r_text.length*Math.random())];
}, 2000);
</script>
You really need to find a tutorial more recent than 1997.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.