<a onclick="go_url(ENCODED-URL);return false;">go to this url</a>
views:
87answers:
4escape and unescape should not be used.See also http://stackoverflow.com/questions/75980/best-practice-escape-or-encodeuri-encodeuricomponent
Mike Samuel
2009-10-01 00:01:22
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
2009-09-30 22:41:14
+1
A:
Use decodeURI()
and encodeURI()
.
The
decodeURI()
function decodes a URI encoded with theencodeURI()
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
2009-09-30 22:48:19
thanks for the edit, the URI version are what you want. escape/unescape encodes for display
Byron Whitlock
2009-09-30 22:50:41
Aye. I did a roll-back on your answer (was confused there for a second) and added my edits to my own.
roosteronacid
2009-09-30 22:53:28