You can't simply hit Return to break the line in a default body, for example. That would make the browser choke. You have to use funny expressions like "%20" or "%A0%B0" instead. But what do they mean, and when should you use which?
The strange compilations of characters are hex codes of ASCII characters that are required to be encoded in URLs by RFC 1738 - Uniform Resource Locators (URL).
How do I know which to use when?
All we need to do is to replace any occurrence of a string in our URL with the function "encodeURIComponent()" which gets our string as an argument.
For example: we want to create a mailto URL that initiates a message to email@example.com with a subject of "When, when is now? (if "now" is here)". Basically, the URL will look like this:
where <subject> is our string "When, when is now? (if "now" is here)". The string as an argument to encodeURIComponent() makes the following: encodeURIComponent("When, when is now? (if \"now\" is here)"). The result of this function call is:
You probably have wondered whence the backslashes came. Their job is escaping the quotation marks used to enclose a string. If a quotation sign appeared within a string without being escaped the interpreter would read this as the end of the string — and be confused (try it).
Now what does our URL look like in its full glory if we put the escaped expression where the <subject> was?
mailto:firstname.lastname@example.org?subject=encodeURIComponent("When, when is now? (if \"now\" is here)")
That's the theory. Unfortunately, realiter it does not work. What's wrong?
Using encodeURIComponent() with mailto URLs
I guess an example says more than 1001 words here (the line breaks are here only to ensure proper formatting of this page; you would write all the code into one single line):