Search code examples
javascripttwitter

insert line break in tweet from URL?


So I have a script like this now: popUp("https://twitter.com/intent/tweet?text=" + greeting + poem + " -&url=" + siteURL, 704, 260);

The "poem" is a haiku and I'd love to have it like: line1 line2 line3

rather than line 1 // line 2 // line 3, which it is now. I tried inserting stuff like \n in there to no avail. "Poem" is constructed simply like line1 + " // " + line2 ...


Solution

  • As you've guessed, newline characters cannot appear in URLs.
    Using a random escaping mechanism won't do you any good; you need to URL-encode the newline:

    https://twitter.com/intent/tweet?text=abc%0adef