escaping bookmarklet code

H

HopfZ

When publishing bookmarklets, we put the bookmarklet code in anchor tag
like this:
<a href="javascript: alert('test');"> name </a>

Some characters of the code need to be escaped. For example, double
quotes need to be escaped as %22 like in this example:
<a href="javascript: var doubleQuote = '%22'; alert(doubleQuote);">
name </a>

Question: Is double quotes the only thing that need to be escaped?

I have seen examples of escaping spaces as %20, but it seems
unnecessary in most browsers i have used.

Thanks in advance.
 
D

David Dorward

HopfZ said:
Some characters of the code need to be escaped. For example, double
quotes need to be escaped as %22 like in this example:
<a href="javascript: var doubleQuote = '%22'; alert(doubleQuote);">
Question: Is double quotes the only thing that need to be escaped?

No, see http://www.faqs.org/rfcs/rfc1738.html (section 2.2)
I have seen examples of escaping spaces as %20, but it seems
unnecessary in most browsers i have used.

Browsers are pretty good at compensating for errors - but you shouldn't take
that as carte blanche to make those errors.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top