0

i have a value

abc}efg

i need it to pass from URL

in HTML } = }  
in URL } = %7D

how to convert } to %7D?

Jared Farrish
  • 48,585
  • 17
  • 95
  • 104
user794624
  • 367
  • 1
  • 5
  • 11

3 Answers3

1

encodeURIComponent combined with How to decode HTML entities using jQuery?.

jQuery's .html() function is basically a thin function wrapper around the widely-supported (vanilla DOM) innerHTML property, so the linked question is still applicable if you're not using jQuery.

Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
0

The function was named encodeURIComponent, and fortunately it's a built-in funciton. You can use it for free:

alert( encodeURIComponent("}") ) //-- alert box will show "%7D"
vantrung -cuncon
  • 10,207
  • 5
  • 47
  • 62
  • Sure - but that doesn't address the problem of the HTML entity. You need to deal with 'encodeURIComponent("}")' first – donohoe Aug 02 '13 at 14:45
0

It sounds like you want to:

  1. Decode the URI component
  2. Encode the ASCII component to an HTML entity

So, first of all, I'd recommend an Entity dictionary like this excellent one: http://www.strictly-software.com/scripts/downloads/encoder.js

This should help you out from there:

function browerURLtoEntity( code ) {
    var crypt = {};
        crypt.URI = code;
        crypt.ascii = decodeURLComponent(crypt.URI);
        crypt.entity = Encoder.htmlEncode(crypt.ascii);
    return crypt;
}
// crypt.entity will be the piece that you want.
buzzedword
  • 3,108
  • 3
  • 21
  • 26