2

I have made a phonegap plugin application on android. I am trying to send String value from Java Code to JavaScript using the sendJavaScript API in Phonegap. But I am facing a problem. If the string contains a single quote, then sendJavaScript does not work. Without single quote, it works perfectly fine. Following is the code, in the java file of Plugin class.

String result = "Any text except single quote ";
String SendJS = "javascript:" + SuccessCallBack + "('" + JSONObject.quote(result) +    "')"; 
sendJavaScript(SendJS);

SuccessCallBack - Callback function in the JavaScript.

result - String to be passed to JavaScript Callback.

If the result string contains a single quote, then sendJavaScript does not work.

Any Suggestions?

4

1 回答 1

2

在使用http://commons.apache.org/lang/api-2.4/org/apache/commons/lang/StringEscapeUtils.html(JS或 HTML 之一)发送之前转义字符串。在 JS 端使用 unescape(string) 取消它,这应该可以帮助你。

于 2012-09-11T07:39:38.640 回答