tags:

views:

87

answers:

4
<a onclick="go_url(ENCODED-URL);return false;">go to this url</a>
A: 

encodeURI(ENCODED-URL);

ScottKoon
A: 

Well you can use escape() and unescape().

Byron Whitlock
escape and unescape should not be used.See also http://stackoverflow.com/questions/75980/best-practice-escape-or-encodeuri-encodeuricomponent
Mike Samuel
A: 

You mean something like this?

<script type="text/javascript">

function go_url(url) {
   var u = '';
   for (var i = 0; i < url.length; i++) {
      u += String.fromCharCode(url.charCodeAt(i) ^ 7);
   }
   window.location.href = u;
}

</script>

<a href="#" onclick="go_url('ossw=((ppp)`raaf)dhj');return false;">yeah</a>
Guffa
+1  A: 

Use decodeURI() and encodeURI().

The decodeURI() function decodes a URI encoded with the encodeURI() function.

The encodeURI() function encodes a string as a URI.

Unlike escape() and unescape() these functions are specifically designed to handle URI-encoding/decoding.

roosteronacid
thanks for the edit, the URI version are what you want. escape/unescape encodes for display
Byron Whitlock
Aye. I did a roll-back on your answer (was confused there for a second) and added my edits to my own.
roosteronacid