Reputation: 1985
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
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,"&").replace(/>/g,">");
}
Upvotes: 0
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
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