Description

Escapes special JavaScript characters, such as single-quotation mark, double-quotation mark, and newline.

Returns

A string that is safe to use with JavaScript.

Category

Syntax

JSStringFormat(string)

Parameters

Parameter

Description

string

A string or a variable that contains one.

Usage

Escapes special JavaScript characters, so you can put arbitrary strings safely into JavaScript.

Example

<cfscript>
    stringValue = "An example string value with a tab chr(8), 
a newline (chr10) and some ""quoted"" 'text'"
    jsStringValue = JSStringFormat(#stringValue#)
    writeOutput(jsStringValue) // An example string value with a tab chr(8), \na newline (chr10) and some \"quoted\" \'text\'
</cfscript>

Output

An example string value with a tab chr(8), \na newline (chr10) and some \"quoted\" \'text\'

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy