Re: Javascript escape & JScript GlobalObject.escape
From: bruce barker (nospam_brubar_at_safeco.com)
Date: 03/15/04
- Next message: Randall: "RE: Accessing Variables in HTML Code"
- Previous message: Scott Allen: "Re: Application wide Functions and Connections"
- In reply to: Hugo Wetterberg: "Javascript escape & JScript GlobalObject.escape"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 15 Mar 2004 10:48:08 -0800
escape is a url escape and single quotes are legal in urls, so no escaping
required. if your are outputing a javascript literal, you need to do
javascript quoting (no builtin function for this). but easy to write.
public static string JscriptQuote(string s)
{
s = s.Replace("'", "\\'");
s = s.Replace("\n", "\\n");
s = s.Replace("\r", "");
return "'" + s + "'";
}
-- bruce (sqlwork.com)
"Hugo Wetterberg" <hugo@wetterberg.com> wrote in message
news:1ssb50pcb9j9bc56ut6qqgqijjeq3is3oo@4ax.com...
> I've got a problem with the escape function in JScript.
> It simply doesn't escape the single quotation mark '
>
> This becomes a problem when I have to construct javascript calls.
> I'm trying to pass the url
> ref_handler.aspx?id=someguid&name=O'Brien
> as a parameter to a javascript function.
>
> What should have been:
> javascript:PopUp('ref_handler.aspx%3fid%3dsomeguid%26name%3dO%27Brien')
> becomes
> javascript:PopUp('ref_handler.aspx%3fid%3dsomeguid%26name%3dO'Brien')
>
> And this, of course, works just about as well as my latest perpetual
> motion machine.
>
> Comments?
>
> Cheers Hugo
- Next message: Randall: "RE: Accessing Variables in HTML Code"
- Previous message: Scott Allen: "Re: Application wide Functions and Connections"
- In reply to: Hugo Wetterberg: "Javascript escape & JScript GlobalObject.escape"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|