威压诸天万界 2018-02-02 08:41 采纳率: 0%
浏览 1746
已结题

android html 交互 安卓低版本 html5的formdata失效

1.我的webview,设置了很多
WebSettings webSettings = allWebview.getSettings();
//设置可与js交互
webSettings.setJavaScriptEnabled(true);
// 把图片加载放在最后来加载渲染
webSettings.setBlockNetworkImage(true);

    //支持插件
    webSettings.setPluginState(WebSettings.PluginState.ON);
    //有无网络时的缓存
    if (JudgeNetwork.isNetworkConnected(context)) {
        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);//根据cache-control决定是否从网络上取数据。
    } else {
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);//没网,则从本地获取,即离线加载
    }

    // 可以读取文件缓存(manifest生效)
    webSettings.setAllowFileAccess(true);
    // 设置可以使用localStorage
    webSettings.setDomStorageEnabled(true);
    // 应用可以有数据库
    webSettings.setDatabaseEnabled(true);
    String dbPath = context.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    webSettings.setDatabasePath(dbPath);
    // 启用地理定位
    webSettings.setGeolocationEnabled(true);
    // 设置定位的数据库路径
    webSettings.setGeolocationDatabasePath(dbPath);
    // 设置编码格式
    webSettings.setDefaultTextEncodingName("utf-8");
    // 设置了这个,页面中就不会出现两边白边了
    allWebview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

// 支持跨域请求
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
webSettings.setAllowUniversalAccessFromFileURLs(true);
// 应用可以有缓存
webSettings.setAppCacheEnabled(true);
String appCaceDir = context.getApplicationContext().getDir("cache", Context.MODE_PRIVATE).getPath();
webSettings.setAppCachePath(appCaceDir);
// 默认使用缓存(前面进行了设置)
// webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
// 设置缓存最多可以有8M
webSettings.setAppCacheMaxSize(8 * 1024 * 1024);
allWebview.requestFocus();//触摸焦点起作用
allWebview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);//取消滚动条
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);//设置允许js弹出alert对话框
// webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);//允许混合内容,5.0之后的api
webSettings.setSaveFormData(true);
2.这个是html5的关键代码,其中alert(form.get("userId"));这个弹不出来,这个在7.0和6.0上面是弹出值的,但是在4.4.4和5.1上面则不能弹出值,也就是userId为空了
var form = new FormData(document.getElementById("patternForm"));
form.append("userId",userId);
alert(form.get("userId"));

  • 写回答

2条回答 默认 最新

  • doctorzhong 2018-02-02 09:50
    关注
    private class webViewClient extends WebChromeClient {
        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            return super.onJsAlert(view, url, message, result);
        }}
            当webview里的页面有alert时,会回调这个方法,你可以自己写一个原生的dailog弹出来
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果