Android WebView和js交互过程中遇到这个问题:[INFO:CONSOLE(1)] “Uncaught SyntaxError: missing ) after argument list”,
android传递ueditor的数据到html中时,不显示内容,控制台只显示一条信息:[INFO:CONSOLE(1)] “Uncaught SyntaxError: missing ) after argument list”, 猜想是转义导致的,java base64加密,js解密,再设置到ueditor中; 只用window.atob()解码,还是报错:Uncaught DOMException: Failed to execute ‘atob’ on ‘Window’: The string to; 原因就是:编码的字符串中含有“-”或者“_”。最终代码如下:
String result = Base64.encodeToString(content.getBytes(), Base64.NO_WRAP | Base64.NO_PADDING | Base64.URL_SAFE);
webView.loadUrl("javascript:setContent('" + result + "')");
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>ueditor demo</title>
</head>
<body>
<script id="container" name="content" type="text/plain">
</script>
<script type="text/javascript" src="ueditor.config.js"></script>
<script type="text/javascript" src="ueditor.all.js"></script>
<script type="text/javascript">
function setContent(content){
var ue = UE.getEditor('container',{
wordCount:false,
elementPathEnabled:false,
});
ue.ready(function(){
ue.setDisabled();
var result = decodeURIComponent(escape(window.atob((content).replace(/-/g, "+").replace(/_/g, "/"))));
ue.setContent(result);
});
}
</script>
</body>
</html>
|