How to display special html characters properly via javascript -


i'm using javascript asp.net server variables display them, problem if have html special character string isn't being assigned it's on server , displays wrong.

for example string :

`alberto gÓmez sÁnchez`  

is displaying

`alberto gómez sánchez` 

i know use replace function doing every possible special html character seems time consuming... guess there must built-in function solves cannot find or easier method trying replace every possible html special character.

do know way? help.

if want decode html string use way:

function decodehtmlentities (str) {     if(str && typeof str === 'string') {       // strip script/html tags       str = str.replace(/<script[^>]*>([\s\s]*?)<\/script>/gmi, '');       str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, '');       element.innerhtml = str;       str = element.textcontent;       element.textcontent = '';     }      return str;   } 

taken here: html entity decode

if want put html string dom, don't need decode it, browser job you. insert this:

$("body").html(encodedhtmlstringfromserver); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -