public static String escapeJavaScriptString(String input) {
        StringBuilder retVal = new StringBuilder(input.length() + 10);
        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            switch (c) {
                case '"':case '\\':
                    retVal.append('\\').append(c);
                    break;
                case '\n':
                    retVal.append("\\n");
                    break;
                case '\r':
                    retVal.append("\\r");
                    break;
                case '\t':
                    retVal.append("\\t");
                    break;
                default:
                    retVal.append(c);
            }
        }
        return retVal.toString();

    }