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"));