Quote Generator - Twitter button

Quote Generator - Twitter button
0

#1

Hi,

Can’t seem to get my twitter button to display the quote (or anything at all) when I click on it. Any ideas why? Not getting any errors either which is leaving me a bit stumped.

Codepen below

https://codepen.io/KUBIX90/pen/mMZRrG


#2

Change your a tag to:

<a target="_blank" id="tweetButton" href="" data-size="large">Tweet</a>

and get rid of all this:

//--Twitter button JS fucntionality
window.twttr = (function(d, s, id) {
	var js, fjs = d.getElementsByTagName(s)[0],
		t = window.twttr || {};
	if (d.getElementById(id)) return t;
	js = d.createElement(s);
	js.id = id;
	js.src = "https://platform.twitter.com/widgets.js";
	fjs.parentNode.insertBefore(js, fjs);
	t._e = [];
	t.ready = function(f) {
		t._e.push(f);
	};
	return t;
}(document, "script", "twitter-wjs"));

because you don’t need it now.


#3

I’ve done the above, tweeting seems OK for some quotes, but seems to mess up some that are on multiple lines. Do I need to use the replace(function) to help amend this and also get rid of the

tags?

Thanks for your help


#4

Only one line is needed to open message-display for twitter:
window.open("https://twitter.com/intent/tweet?hashtags=quote&text=" + string);
where string variable is your quote. Put this line in ‘click’ handler and that should be all. Also twitter has character limit.


#5

Try use .text instead of .html