In Google and on some sites instead of a space is "+", but for example in js encodeURI does instead of a space "% 20". How can I make a "+" in js ??

  • Sorry for the inappropriate (stupid) question. And instead of + on these sites in the URL should use% 2b? - avp
  • No, I should have been the other way around, and how they already helped me - trane294
  • You did not understand. I became interested in myself. If the space is replaced in the URL by "+", then what to write in the same URL instead of a plus? Hex code of the symbol "+" 2b. Those. do you need "% 2b"? Who knows ? - avp
  • one
    In this case, yes% 2B - trane294

2 answers 2

By the way, in JS there is also an encodeURIComponent .

I usually expand my string class with my method like this:

String.prototype.escapeURI = function () { return encodeURIComponent(this).replace(/%20/g, '+'); } //... encoded_param = "foo bar".escapeURI(); // => foo+bar 

    Something like this:

     if(location.href.match(/%20/ig)) { location.href = encodeURI(location.href.replace(/%20/ig, '+')); } else { return false; }