public static String escapeJavaScript(String source) {

        source = CmsStringUtil.substitute(source, "\\", "\\\\");
        source = CmsStringUtil.substitute(source, "\"", "\\\"");
        source = CmsStringUtil.substitute(source, "\'", "\\\'");
        source = CmsStringUtil.substitute(source, "\r\n", "\\n");
        source = CmsStringUtil.substitute(source, "\n", "\\n");

        // to avoid XSS (closing script tags) in embedded Javascript
        source = CmsStringUtil.substitute(source, "/", "\\/");
        return source;
    }
public static String escapeJavaScript ( String source ) { source = CmsStringUtil . substitute ( source , "\\" , "\\\\" ) ; source = CmsStringUtil . substitute ( source , "\"" , "\\\"" ) ; source = CmsStringUtil . substitute ( source , "\'" , "\\\'" ) ; source = CmsStringUtil . substitute ( source , "\r\n" , "\\n" ) ; source = CmsStringUtil . substitute ( source , "\n" , "\\n" ) ; source = CmsStringUtil . substitute ( source , "/" , "\\/" ) ; return source ; }
Escapes a String so it may be used in JavaScript String definitions.<p>

This method escapes
line breaks (<code>\r\n,\n</code>) quotation marks (<code>".'</code>)
and slash as well as backspace characters (<code>\,/</code>).<p>

<b>Directly exposed for JSP EL</b>, not through {@link org.opencms.jsp.util.CmsJspElFunctions}.<p>

@param source the String to escape

@return the escaped String