perlcgi has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
First of all if you hate JavaScript, read no further dear Monk. Please don't downvote me, as I think this is an interesting chicken and egg problem that may interest many Monks, who some some day may encounter the same situation.
I am working with a HTML templating system, that is essentially, a black box. I cannot configure/hack it in any way. But I need to munge the expanded template codes for presentation, so I'm guessing the only tool I can use is JavaScript. (PerlScript here is not an option) For example the template code $123 might expand into "Hello World". Normally something like this works fine:
Is there a way to escape apostrophes and inverted comma characters before their assignment in JavaScript? Or is there some JavaScript trick to accommodate this situation?
I'd be obliged for any help Monk, and am thankful for your patience in allowing yourself to be exposed to this question.
perlcgi
First of all if you hate JavaScript, read no further dear Monk. Please don't downvote me, as I think this is an interesting chicken and egg problem that may interest many Monks, who some some day may encounter the same situation.
I am working with a HTML templating system, that is essentially, a black box. I cannot configure/hack it in any way. But I need to munge the expanded template codes for presentation, so I'm guessing the only tool I can use is JavaScript. (PerlScript here is not an option) For example the template code $123 might expand into "Hello World". Normally something like this works fine:
But if the template code expands into "Hello Fred's World" then you'll get a syntax error as the apostrophe in Fred's is interpreted as the end of the string.<script> var field = '$123'; document.write ('field'); </script>
Is there a way to escape apostrophes and inverted comma characters before their assignment in JavaScript? Or is there some JavaScript trick to accommodate this situation?
I'd be obliged for any help Monk, and am thankful for your patience in allowing yourself to be exposed to this question.
perlcgi
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Template-output quoting (Warning: Contains JavaScript)
by dingus (Friar) on Dec 09, 2002 at 18:06 UTC | |
Re: Template-output quoting (Warning: Contains JavaScript)
by tachyon (Chancellor) on Dec 10, 2002 at 14:50 UTC | |
by perlcgi (Hermit) on Dec 11, 2002 at 10:34 UTC | |
by tachyon (Chancellor) on Dec 11, 2002 at 11:19 UTC | |
by perlcgi (Hermit) on Dec 11, 2002 at 12:49 UTC |
Back to
Seekers of Perl Wisdom