ASP
Here you can find some FREE usefull Classic ASP / VBScript code snippets, class modules, etc.
Function Escape(String)String
Escapes known characters on Strings so they can be safely used in Javascript.
Example
<% dim my_string my_string = "Is this a 'safe string' for Javascript (y/n)?" response.write "<script language='javascript'>" response.write "window.alert('" & Escape(my_string) & "');" response.write "</script>" ' this will display a Javascript alert message. ' If you don't use the Escape() function you'll get a Javascript error. %> Source Code <%
function Escape(byval s) if instr(s,"\")>0 then s=replace(s,"\","\\") if instr(s,"/")>0 then s=replace(s,"/","\/") if instr(s,"'")>0 then s=replace(s,"'","\'") if instr(s,"""")>0 then s=replace(s,"""",""") if instr(s,vbcr)>0 then s=replace(s,vbcr,"\r") if instr(s,vblf)>0 then s=replace(s,vblf,"\n") if instr(s,vbtab)>0 then s=replace(s,vblf,"\t") escape=s end function %> |