beta.blog

JavaScript: Decode URL (online example + source)

by on May.25, 2011, under Programming

The following sample form will allow you to encode and decode URLs using java script:

Source code:

<script type='text/javascript'>

  function encode()
  {
    document.getElementById('textArea').value = encodeURIComponent(document.getElementById('textArea').value);
  }

  function decode()
  {
    document.getElementById('textArea').value = decodeURIComponent(document.getElementById('textArea').value.replace(/\+/g,  " "));
  }

</script>

Don’t forget to replace textArea with the ID of your text area.
The above code is similar to the PHP function urldecode.


Leave a Reply

*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!