Krishna
Krishna

Reputation: 1985

Display special characters in page

I'm having one div which will display some text. I'm getting this text from DB. This text can contains special characters like "\",">","<" etc. When I'm trying to display this text in my page, these special characters wont be visible in my page for obvious reasons. So how to handle this situation.

Upvotes: 0

Views: 89

Answers (3)

abcd
abcd

Reputation: 3210

Write a function on java side which will convert all these or expected special characters and will return to front end.

e.g.

function String convert(String var){
var.replace(/&/g,"&amp;").replace(/>/g,"&gt;");
}

Upvotes: 0

Jayaram
Jayaram

Reputation: 1725

in your javascript you can write function, which will replace all the special characters with code

have a look at this answer Convert special characters to HTML in Javascript

Upvotes: 1

npinti
npinti

Reputation: 52185

Since you have mentioned database, I am assuming that you have Java involved...

That being said, you can take a look at Apache's StringEscapeUtils and escape your strings accordingly.

Upvotes: 2

Related Questions