Saturday, January 3, 2009

Mortgage Referall Cards

JAVASCRIPT - HtmlEncode

And here I may have found (in most tested and correct) a simple function to do the ' HtmlEncode (ASP function) client-side! It was about time! : D

This is a small javascript that you insert in your pages!

I tested (and changed where you had problems) this script with the following browsers: Microsoft Internet Explorer
  • 6.7
  • Mozilla Firefox 3
  • Opera Google Chrome Apple Safari


function is as follows:



\u0026lt;script type="text/javascript"> \u0026lt;! -
HTMLEncode function (str) {
was p = document.createElement ('div');
was text = document.createTextNode (str);
div.appendChild (text);
text = div.innerHTML;
text.replace text = (/ "/ g, """);

/ / Easier accentate -------------

text = text.replace (/ à / g, "à") ;
text = text.replace (/ è / g, "è");
text = text.replace (/ é / g, "é");
text = text.replace (/ ì / g, "ì");
text = text.replace (/ ù / g, "ù");
text.replace text = (/ o / g, "ò");

//-------------------------
//------- ------- ------- Fix Safari problem
text.replace text = (/ \u0026lt;/ g, "<");
text text.replace = (/> / g, ">");
//---------------------------- ----
return text;}


//--> \u0026lt;/ script>

Just call it and pass as parameter the text you want to do the encode. The function returns the encrypted text!

For now I noticed that not all special characters are supported! For example, the symbol grades -> ° that remains (in my car with my settings), while the ASP HtmlEncode ° translates it into (or ° depending on the settings of the server)!! In short, you can not have everything in life but broadly it may already be enough! : D
If someone wants to stand there and can try them all!

Who is invited to experience problems should report them in a comment on this post that maybe we can try to fixarli! ;)

the prox!

0 comments:

Post a Comment