In alt.www.webmaster, Boobie wrote:
[color=blue]
> I need to escape HTML chracters so <test> --> <test>
>
> Looks like there is no built-in JS function...anyo ne got one handy?[/color]
I don't do JavaScript, but I do have a question: what happens with
the 10-15% of your visitors who have JavaScript disabled or
unavailable in their browsers?
Writing in news:alt.www.webmaster,comp.lang.javascript
From the safety of the Shagnasty Software cafeteria
Beauregard T. Shagnasty <a.nony.mous@ex ample.invalid> said:
[color=blue]
> In alt.www.webmaster, Boobie wrote:
>[color=green]
>> I need to escape HTML chracters so <test> --> <test>
>> Looks like there is no built-in JS function...anyo ne got one handy?[/color]
>
> I don't do JavaScript, but I do have a question: what happens with the
> 10-15% of your visitors who have JavaScript disabled or unavailable in
> their browsers?[/color]
hrmm, O/P is not specific - this /could/ be a server-side JS question?
--
William Tasso - Do not meddle in the affairs of dragons, for you are
crunchy and good with ketchup.
In alt.www.webmaster, William Tasso wrote:[color=blue]
> Writing in news:alt.www.webmaster,comp.lang.javascript From the
> safety of the Shagnasty Software cafeteria Beauregard T. Shagnasty
> <a.nony.mous@ex ample.invalid> said:
>[color=green]
>> In alt.www.webmaster, Boobie wrote:
>>[color=darkred]
>>> I need to escape HTML chracters so <test> --> <test>
>>> Looks like there is no built-in JS function...anyo ne got one
>>> handy?[/color]
>>
>> I don't do JavaScript, but I do have a question: what happens
>> with the 10-15% of your visitors who have JavaScript disabled or
>> unavailable in their browsers?[/color]
>
> hrmm, O/P is not specific - this /could/ be a server-side JS
> question?[/color]
You have a point, Mr. Tasso. At this late hour, I can't think of a
reason to do it client-side. (Speaking of late hours, did you just
crawl out of bed? <g>)
"Boobie" schrieb:
[color=blue]
> I need to escape HTML chracters so <test> --> <test>
>
> Looks like there is no built-in JS function...anyo ne got one handy ?[/color]
What about replace()? ;-)
But as the others said, you should consider doing this on the server
side instead of the client side.
Boobie wrote:[color=blue]
> I need to escape HTML chracters so <test> --> <test>
>
> Looks like there is no built-in JS function...anyo ne got one handy ?[/color]
On Sun, 18 Sep 2005, Boobie wrote:
[color=blue]
> I need to escape HTML chracters so <test> --> <test>
>
> Looks like there is no built-in JS function...anyo ne got one handy ?
>
> thanks[/color]
Completely untested and could possible reflect my complete
misunderstandin g of JavaScript:
function myescape (foo) {
myfoo = '';
for (i=0;i<length(f oo);i++)
{ myfoochar = foo.charAt(i);
if (myfoochar == '<') myfoochar = '<';
if (myfoochar == '>') myfoochar = '>';
if (myfoochar == '&') myfoochar = '&';
// add any other characters you want to handle here
myfoo += myfoochar;
}
return myfoo;
}
....
....
oldbar = '<test>';
newbar = myescape(oldbar );
// newbar should be '<test> '
....
....
--
``Why don't you find a more appropiate newsgroup to post this tripe into?
This is a meeting place for a totally differnt kind of "vision impairment".
Catch my drift?'' -- "jim" in alt.disability. blind.social regarding an
off-topic religious/political post, March 28, 2005
Boobie wrote:[color=blue]
> I need to escape HTML chracters so <test> --> <test>
>
> Looks like there is no built-in JS function...anyo ne got one handy ?
>
> thanks[/color]
You could fake it using the encodeURI function in JS;
On 19 Sep 2005, SpaceGirl wrote:
[color=blue]
> Boobie wrote:[color=green]
> > I need to escape HTML chracters so <test> --> <test>
> >
> > Looks like there is no built-in JS function...anyo ne got one handy ?
> >
> > thanks[/color]
>
> You could fake it using the encodeURI function in JS;
>
> See -
>
> http://webcoder.info/reference/URIEsc.html
>
> It's really for encoding query strings, but I guess it could also be
> used for encoding pages as it converts all non-alpha characters.[/color]
Unless I am totally misunderstandin g the documentation for the encodeURI
function, it won't encode '<' and '>' as '<' and '>' but as '%3C'
and '%3E'.
--
``Why don't you find a more appropiate newsgroup to post this tripe into?
This is a meeting place for a totally differnt kind of "vision impairment".
Catch my drift?'' -- "jim" in alt.disability. blind.social regarding an
off-topic religious/political post, March 28, 2005
And lo, Boobie didst speak in alt.www.webmaster,comp.lang.javascript:
[color=blue]
> I need to escape HTML chracters so <test> --> <test>
>
> Looks like there is no built-in JS function...anyo ne got one handy ?[/color]
--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#sear - Orca Search - PHP/MySQL site
search engine
Boobie wrote:[color=blue]
> I need to escape HTML chracters so <test> --> <test>
>
> Looks like there is no built-in JS function...anyo ne got one handy ?
>
> thanks[/color]
This is taken from "Prototype. js". The best i have ever seen.
escapeHTML: function() {
var div = document.create Element('div');
var text = document.create TextNode(this);
div.appendChild (text);
return div.innerHTML;
},
unescapeHTML: function() {
var div = document.create Element('div');
div.innerHTML = this.stripTags( );
return div.childNodes[0].nodeValue;
}
});
JRS: In article <DUqXe.81416$EX .22865@twister. nyroc.rr.com>, dated Mon,
19 Sep 2005 04:12:19, seen in news:comp.lang. javascript, Beauregard T.
Shagnasty <a.nony.mous@ex ample.invalid> posted :
[color=blue][color=green]
>> hrmm, O/P is not specific - this /could/ be a server-side JS
>> question?[/color]
>
>You have a point, Mr. Tasso. At this late hour, I can't think of a
>reason to do it client-side.[/color]
There may be no server-side processing. Most of my javascript pages
indirectly use replacement of & < > yet none of them use a server
except for initial delivery :
JRS: In article <V%qXe.150$zQ3. 108@newsread1.n ews.pas.earthli nk.net>,
dated Mon, 19 Sep 2005 04:20:05, seen in news:comp.lang. javascript, Dr Clue
<ianstormsfw@mi ndspring.com> posted :
[color=blue]
> ...
> .split("&").joi n("&").spli t("<").join("&l t;").split(">") .join(">")
>[/color]
Have you compared, in various browsers, the speed of that on comparison
with the perhaps more obvious RegExp method? I find it to be annoyingly
quicker.
Dr John Stockton wrote:[color=blue]
> JRS: In article <DUqXe.81416$EX .22865@twister. nyroc.rr.com>, dated Mon,
> 19 Sep 2005 04:12:19, seen in news:comp.lang. javascript, Beauregard T.
> Shagnasty <a.nony.mous@ex ample.invalid> posted :
>
>[color=green][color=darkred]
>>>hrmm, O/P is not specific - this /could/ be a server-side JS
>>>question?[/color]
>>
>>You have a point, Mr. Tasso. At this late hour, I can't think of a
>>reason to do it client-side.[/color]
>
>
> There may be no server-side processing. Most of my javascript pages
> indirectly use replacement of & < > yet none of them use a server
> except for initial delivery :
>
> function SafeHTML(S) {
> return S.replace(/&/g, "&").
> replace(/</g, "<").replace (/>/g, ">") }
>[/color]
Exactly. Initial delivery should replace them before they go to the
client. Your way will fail when the user has javascript turned off.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. jstucklex@attgl obal.net
=============== ===
Comment