开发者

any javascript buildin function to convert html entity to pass from url

开发者 https://www.devze.com 2023-04-10 11:49 出处:网络
i have a value 开发者_如何学运维abc}efg i need it to pass from URL in HTML } = }

i have a value

开发者_如何学运维abc}efg

i need it to pass from URL

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

how to convert } to %7D?


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.


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"


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.
0

精彩评论

暂无评论...
验证码 换一张
取 消