unescape method in javascript

Asked

Viewed 80 times

3

I’m having second thoughts on script down below:

function getURLParam(name) {
   var regex = "[\\?&]"+name+"=([^&#]*)";

//mais código
   return unescape(results[1]);

I’m new to javascript, I can’t understand what that is:

return unescape(results[1]); 
  • What that part does ?
  • Why did you need to use this ?

1 answer

4


unescape is a deprecated method, but its function is to turn hexadecimal characters into "normal" characters. For example

unescape("%E4%F6%FC");  // dá "äöü"

The part return I assume you know, this is what indicates to the function that it should return the value that comes next.

The part results[1] and var regex = "[\\?&]"+name+"=([^&#]*)"; give me the idea that you have a .match somewhere and then the [1] is the second element/result of a match which is precisely the value found. Because the .match has in the first element of the array that returns the full string and in the second (and remaining) the result itself.

  • So what say he will take the second element of the array? but I do not know what he will do with that return...

  • 1

    @gonz I also do not know because I have no idea what code you have :) If you put this in the question I may help more. The function name getURLParam hint. Have any idea why this function exists in your code?

  • It takes data from the url, as an example: ?text=impressao&port=LPT1. And this javascript function sends to the java applet to handle the received data.

  • @gonz already figured out what you were looking for? For example in this example you put, making var porta = getURLParam('port'); this variable porta will receive the value LPT1.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.