How to Encode URLs in JavaScript

JavaScript (JV) is one of the most widely used computer programming language. It was first developed for the web browsers in order to promote communication between the clients and users, to control the web browser and to change the content of the document. However, with the passage of time, it was also used to create different dynamic scripts for the web pages with the integration of various other programming languages like C.

It is not very difficult to encode a URL in JV. You just have to keep in mind few things which have been mentioned in the given steps to get the job done.

Instructions

  • 1

    First of all, you have to locate the file which you want to encode. You can either create an HTML file or directly a JV file. It is extremely important for you to use the right codes in your file, otherwise you will not be able to execute them. Moreover, you also have to open and close the tags in the right way.

  • 2

    After locating the file in your computer, you have to right-click on it. You will see some options, keep your cursor on ‘Open With’ and then select your own editor.

  • 3

    Now, you have to create the encoded URL. You must know that each character of the URL will have its own encoding series which you have to follow in order to get the desired results. For example, in this URL “var url = http://site.com/index.php?name=joe%3Asmith”, you can see the colon between the first and last names of the user.

  • 4

    Then, you must forward the user. After encoding the URL, you will have to embed it in your own script which you wrote so as to redirect it. You will not be able to encode your URL in the JV until or unless you embed your script with the encoded URL. Besides, you have to follow the above mentioned steps in sequence, otherwise the code will not execute the required results. In order to send the user to the encoded URL, you can use the code “windows.location.href=url;” in your programme.

Leave a Reply

Your email address will not be published. Required fields are marked *


four + 8 =