Tweeting quotes, semicolons and encodeURIComponent

Tweeting quotes, semicolons and encodeURIComponent
0

#1

Hi. I have just finished my random quote machine. I was messing around with it a little bit to check if everything works correctly, and i have noticed, that if the quote has any semicolons in it’s text, my tweeting function will only pass the text up to that semicolon and nothing more.

Here’s the link to pen

Now, Ive read that solution to this problem would be using the encodeURIComponent function, but I’m not sure how to use it to make it work. I tried:
var tweetURL = encodeURIComponent("https://twitter.com/intent/tweet?text=" + $('.quote').text() + " \n" + $('.author').text());

and also:
var tweetURL = "https://twitter.com/intent/tweet?text=" + encodeURIComponent($('.quote').text() + " \n" + $('.author').text());

Both did nothing. How exactly am I supposed to use this function? MDN and other sources are kind of vague on that matter ;/.


#2

Try this:

var tweetURL = "https://twitter.com/intent/tweet?text=" +
encodeURIComponent($('.quote').text()) + " \n" + $('.author').text();