How to url encode in JavaScript

Sheonarayan
Posted by Sheonarayan under JavaScript category on | Points: 40 | Views : 628
To encode the url in JavaScript, following javascript built in functions can be used.

1. encodeURIComponent(string) - to encode querystring parts only

<script>
var url = "http://www.dotnetfunda.com" + encodeURIComponent('variables in C# artilces');
</script>


2. encodeURI(string) - to encode complete url

<script>
var url = "http://www.dotnetfunda.com" + encodeURI('variables in C# artilces');
</script>



Thanks

Comments or Responses

Login to post response