Groups > Design > Macromedia DreamWeaver > Re: javascript htmlencode/decode?




javascript htmlencode/decode?

javascript htmlencode/decode?
Thu, 10 Apr 2008 10:33:54 -050
I have a function that will insert HTML into a text editor box. It'll look 
like this:

editor.insert('my string')

The problem is if mystring has characterts that need to be escaped. ie:

editor.insert('<a href="link">I can't run as well as 'Mr. Mike'.
I'm tired 
and said "you go without me, mike!"</a>')

The bigger catch is that these strings are going to be rather huge, as they 
are giant chunks of HTML (big tables, etc.)

It doesn't look like javascript offers a htmlencode/decode function but does 
thave the escape/unescape.

unescape would work fine provided I 'escape' my string first. Anyone know of 
a tool, downloadable or online that I can paste in text and have it escaped 
for me for use in a javascript?

-Darrel 

Post Reply
Re: javascript htmlencode/decode?
Thu, 10 Apr 2008 10:43:41 -050
> unescape would work fine provided I 'escape' my string first. Anyone know 
> of a tool, downloadable or online that I can paste in text and have it 
> escaped for me for use in a javascript?

Or, perhaps a different way to solve this...

If I have this string: &lt;table
id=&quot;gatewaytable&quot;&lt;

Is there a prebuilt function in javascript to 'unencode' the html entities 
so it inserts this:

<table id="gatewaytable">

Or would one have to write their own script to manually replace the html 
entities?

-Darrel

Post Reply
Re: javascript htmlencode/decode?
Thu, 10 Apr 2008 10:48:10 -050
>Anyone know of
> a tool, downloadable or online that I can paste in text and have it 
> escaped for me for use in a javascript?

Spoke too soon. Found one:

http://www.the-art-of-web.com/javascript/escape/

-Darrel 

Post Reply
about | contact