Escape from All Code Trash

September 6th, 2005

URL Escaping is what causes those yucky percent-signs and numeric digits to show up sometimes in the middle of your otherwise perfectly legible URLs. These percent-escaped values are necessary because the list of allowed characters for a URL doesn’t cover many of the common punctuation marks we like to use, and also fails to cover the Unicode characters that are more and more common in the international world-wide web.

I was explaining to a client some of the finer details of escaping, and trying to foster an understanding for what needed to be escaped and what didn’t, when it occurred to me that they, like almost everybody reading this post, has at their disposal an excellent reference on URL Escaping: the JavaScript interpreter built into their browser.

Since I discovered the built-in escaping and unescaping functions of JavaScript, I have from time to time taken advantage of them by typing something quickly into the address bar of Safari when I needed to get a quickly readable version:

javascript:alert(unescape(‘Escape%20from%20All%20Code%20Trash’))

To make this is as easy as possible for everyday users (my client, in this case) to take advantage of, I decided to put together a couple “button-bar” compatible JavaScript URLs. Now I keep these in my own toolbar for quickly encoding and decoding URL strings as necessary.

To try them out, just click on the link (from a web browser). To install them, drag them, one at a time, to your bookmarks bar.

Escape URL

Unescape URL

I%20hope%20you%20enjoy%20these%20S%FCper%20Kewl%20Scripts%u2122%21, and please let me know if you have any suggestions for improving them.

2 Responses to “Escape from All Code Trash”

  1. Matt Schinckel Says:

    javascript:unescape(string) will also unescape strings that have been totally escaped: a nice technique for masking email addresses in a page.

    Of course, you need a method for escaping them to begin with. {Smarty} can do this already with it’s escape modifier, which is useful if you are on a system with this installed.

    If you don’t need to do it automatically, you can do it by hand: visit the site below.

    http://sharkysoft.com/tutorials/jsa/content/018.html

    You could use the code from there to create a function if you wanted to.

    I’m using the unescape() function to implement a JavaScript version of Gravatars on my site, that are still obscured from Spambots.

  2. Daniel Jalkut Says:

    Interesting idea. So you’re saying that the email culling bots are just using some raw HTTP fetch, so they won’t have a JavaScript rendered version of the page? Let’s hope that lasts!

Comments are Closed.

Follow the Conversation

Stay up-to-date by subscribing to the Comments RSS Feed for this entry.