Quote Generator - Twitter button


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


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) {
	return t;
}(document, "script", "twitter-wjs"));

because you don’t need it now.

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


Thanks for your help

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.

Try use .text instead of .html