code: private static String escapeJavaScriptChars(String s) {
          StringBuilder sb = new StringBuilder();
          for (int i = 0; i < s.length(); i++) {
              char ch = s.charAt(i);
              switch (ch) {
                  case '\b':
                      sb.append("\\b");
                      break;
                  case '\t':
                      sb.append("\\t");
                      break;
                  case '\n':
                      sb.append("\\n");
                      break;
                  case '\f':
                      sb.append("\\f");
                      break;
                  case '\r':
                      sb.append("\\r");
                      break;
                  case '"':
                      sb.append("\\\"");
                      break;
                  case '\'':
                      sb.append("\\\'");
                      break;
                  case '\\':
                      sb.append("\\\\");
                      break;
                  default:
                      if (ch < 32 || ch >= 127) {
                          sb.append(String.format("\\u%04X", (int)ch));
                      } else {
                          sb.append(ch);
                      }
                      break;
              }
          }
          return sb.toString();
      }
docs: Returns a String with escaped special JavaScript characters.
  
  @param s String that needs to be escaped
  @return a valid escaped JavaScript string