Returns a string that is safe to use with JavaScript.
JSStringFormat(string)
Parameter |
Description |
---|---|
string |
A string |
JSStringFormat
escapes special JavaScript characters, such as single quote, double quote, and newline, so you can put arbitrary strings safely into JavaScript.
<!----------------------------------------------------------- This example illustrates use of the JSStringFormat function. -----------------------------------------------------------> <html> <head> <title>JSStringFormat</title> </head> <body> <H3>JSStringFormat</H3> <cfset stringValue = "An example string value with a tab chr(8), a newline (chr10) and some ""quoted"" 'text'"> <P>This is the string we have created:<BR> <cfoutput>#stringValue#</cfoutput> </P> <cfset jsStringValue = JSStringFormat(#stringValue#)> <!-------------------------------------------------------------------- Generate an alert from the JavaScript string jsStringValue. ----------------------------------------------------------------------> <SCRIPT> s = "<cfoutput>#jsStringValue#</cfoutput>"; alert(s); </SCRIPT> </body> </html>