martinh
November 16, 2009, 4:38pm
1
Hi,
When using HTML sometimes you need to change some characters.
For example if I need to show the text:
Black & White > 100 euro
then this needs to be replaced by
Black & White > 100 euro
I would like to know if there is some standaard function in Servoy or in Javascript that handles this.
I tried to use the escape() function, but replaces also all spaces with %20, so that is not a solution.
I’ve written a method to do this replace myself, but perhaps there are better ways and maybe also faster ways
var _input = arguments[0];
var _output
_output = utils.stringReplace(_input, '&', '&')
_output = utils.stringReplace(_output, '<', '<')
_output = utils.stringReplace(_output, '>', '>')
return _output;
Harjo
November 16, 2009, 4:51pm
2
did you try:
var myEncodedHtml = encodeURIComponent(myHTML)
martinh
November 16, 2009, 5:06pm
3
I tried Harjo, but that also replaces all spaces by %20
I just need only the necessary characters to be replaced that confuses HTML (&, < and >)
or this:
utils.stringEscapeMarkup()
Rob
martinh
November 17, 2009, 9:34am
5
rgansevles:
utils.stringEscapeMarkup()
Thanks Rob,
This results indeed in the output I wanted to see.
I noticed that the second arguments (escapeSpaces) is false by default. Perfect!
So when you want to show some text from your database into HTML (for example article description) then you always have to use this utils.stringEscapeMarkup() to be sure that HTML doesn’t get confused because of &, < or >
Martin