<WebView android:id="@+id/wv_service" android:layout_width="match_parent" android:layout_height="wrap_content"></WebView> 代码行:
webview = (WebView) findViewById(R.id.wv_service);WebSettings webSettings = webview.getSettings();//设置WebView属性,能够执行Javascript脚本webSettings.setJavaScriptEnabled(true);//设置可以访问文件webSettings.setAllowFileAccess(true);//设置支持缩放webSettings.setBuiltInZoomControls(true);//加载需要显示的网页webview.loadUrl(AppConst.SERVER_URL);//设置Web视图webview.setWebViewClient(new webViewClient());
//Web视图private class webViewClient extends WebViewClient { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; }} 注:这样写的话会存在一个高危风险
解除风险需重新设置web视图:
//设置Web视图webview.setWebViewClient(new webViewClient(){ @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { view.removeJavascriptInterface("access..."); view.removeJavascriptInterface("acc..."); }});
WebView.removeJavascriptInterface的方法最低sdk的leave11
<uses-sdk android:minSdkVersion="11"/>
时间: 2024-11-06 17:50:19