html entity decode

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

html entity decode

 
0
  #1
Jul 28th, 2008
anybody have a browser compatible html entity decoding function?
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: html entity decode

 
0
  #2
Jul 28th, 2008
Found this online and it seems like they all use this concept.
  1. function html_entity_decode(str)
  2. {
  3. //jd-tech.net
  4. var tarea=document.createElement('textarea');
  5. tarea.innerHTML = str; return tarea.value;
  6. tarea.parentNode.removeChild(tarea);
  7. }

apparently the innerHTML is giving me a runtime error on ie, i can only use value. But value doesn't decode the html entities.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: html entity decode

 
0
  #3
Jul 28th, 2008
Found a solution:
  1. function html_entity_decode(str)
  2. {
  3. try
  4. {
  5. var tarea=document.createElement('textarea');
  6. tarea.innerHTML = str; return tarea.value;
  7. tarea.parentNode.removeChild(tarea);
  8. }
  9. catch(e)
  10. {
  11. //for IE add <div id="htmlconverter" style="display:none;"></div> to the page
  12. document.getElementById("htmlconverter").innerHTML = '<textarea id="innerConverter">' + str + '</textarea>';
  13. var content = document.getElementById("innerConverter").value;
  14. document.getElementById("htmlconverter").innerHTML = "";
  15. return content;
  16. }
  17. }

this way you can still add the innerHTML, but to a div instead, and it also adds a textarea with it so it can be retrieved by the value of the textarea. then it clears out the div and leaves it blank.
Cat skinned.
Last edited by R0bb0b; Jul 28th, 2008 at 8:31 pm.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC