Javascript escape & JScript GlobalObject.escape

  • Thread starter Thread starter Hugo Wetterberg
  • Start date Start date
H

Hugo Wetterberg

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
 
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)
 
Back
Top