Answered by:
"Unescape" HTML chars?

Question
-
HEllo guys.
While playing with the syndication api, I've noticed that I'm getting escaped chars in it when I put the text inside a textbox. For instance, I'm editing a feed and I've noticed that the title is replacing spaces with . Is there any way to "unescape" this without me having to write my own routine?
thanks,
Luis Abreu
Thursday, June 14, 2012 6:44 PM
Answers
-
Ah...I see the difference now. I am not aware of any built in functions in WinJS. Some people are using a little jQuery hack which may work if you are already using jQuery.
function htmlDecode(value){ return $('<div/>').html(value).text(); }
otherwise a straight DOM version of the same thing:
function htmlDecode(input){ var e = document.createElement('div'); e.innerHTML = input; return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue; }
You still need to write your own method, but at least you're not parsing the text directly.
Code snippets take from here: http://stackoverflow.com/questions/1912501/unescape-html-entities-in-javascript
Dave Paquette @Dave_Paquette www.davepaquette.com
- Marked as answer by Luis Miguel Abreu Friday, June 15, 2012 7:26 AM
Thursday, June 14, 2012 11:56 PM
All replies
-
Have you tried the javascript unescape function?
http://www.w3schools.com/jsref/jsref_unescape.asp
Dave Paquette @Dave_Paquette www.davepaquette.com
Thursday, June 14, 2012 8:33 PM -
It won't work. If I recall correctly, the solution is to build a parsing routine that does that, but I was hoping that this was already part of the WinJS library.
Luis Abreu
Thursday, June 14, 2012 9:05 PM -
Ah...I see the difference now. I am not aware of any built in functions in WinJS. Some people are using a little jQuery hack which may work if you are already using jQuery.
function htmlDecode(value){ return $('<div/>').html(value).text(); }
otherwise a straight DOM version of the same thing:
function htmlDecode(input){ var e = document.createElement('div'); e.innerHTML = input; return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue; }
You still need to write your own method, but at least you're not parsing the text directly.
Code snippets take from here: http://stackoverflow.com/questions/1912501/unescape-html-entities-in-javascript
Dave Paquette @Dave_Paquette www.davepaquette.com
- Marked as answer by Luis Miguel Abreu Friday, June 15, 2012 7:26 AM
Thursday, June 14, 2012 11:56 PM -
Thanks Dave.
I really did expect there to be some sort of builtin helper...oh well :)
thanks again.
Luis Abreu
Friday, June 15, 2012 7:26 AM