Yes, this actually works. You first have to format the MRV for use in Javascript (convert line terminators to UNIX style,escape new line characters,escape single quotes).
This Java method works:
/**
* Converts a string to a format that can be used as a
* value of JavaScript variable in an HTML page.
* Converts line separators to UNIX style and replaces
* new line characters with a backslash and an "n"
* character.
* @param input original string containing line terminators
* @return the modified string.
*/
public static String convertForJavaScript(String input) {
String value = input;
//Converting Windows style string to UNIX style
value = replaceString(value, "\r\n", "\n");
//Converting Macintosh style string to UNIX style
value = replaceString(value, "\r", "\n");
//Converting special characters
value = replaceString(value, "\\", "\\\\");
value = replaceString(value, "\n", "\\n");
value = replaceString(value, "\"", "\\\"");
value = replaceString(value, "'", "\\'");
return value;
}
-John