Java Code Examples for com.tencent.smtt.sdk.WebSettings#setJavaScriptCanOpenWindowsAutomatically()
The following examples show how to use
com.tencent.smtt.sdk.WebSettings#setJavaScriptCanOpenWindowsAutomatically() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: X5WebView.java From TBSVideoPlay with Apache License 2.0 | 6 votes |
/** * 初始化webview设置 */ private void initWebViewSettings() { WebSettings webSetting = this.getSettings(); webSetting.setJavaScriptEnabled(true); webSetting.setJavaScriptCanOpenWindowsAutomatically(true); webSetting.setAllowFileAccess(true); webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); webSetting.setSupportZoom(true); webSetting.setBuiltInZoomControls(true); webSetting.setUseWideViewPort(true); webSetting.setSupportMultipleWindows(true); // webSetting.setLoadWithOverviewMode(true); webSetting.setAppCacheEnabled(true); // webSetting.setDatabaseEnabled(true); webSetting.setDomStorageEnabled(true); webSetting.setGeolocationEnabled(true); webSetting.setAppCacheMaxSize(Long.MAX_VALUE); // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY); webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND); // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH); webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE); }
Example 2
Source File: X5WebView.java From polyvideo with Apache License 2.0 | 6 votes |
private void initWebViewSettings() { WebSettings webSetting = this.getSettings(); webSetting.setJavaScriptEnabled(true); webSetting.setJavaScriptCanOpenWindowsAutomatically(true); webSetting.setAllowFileAccess(true); webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); webSetting.setSupportZoom(true); webSetting.setBuiltInZoomControls(true); webSetting.setUseWideViewPort(true); webSetting.setSupportMultipleWindows(true); // webSetting.setLoadWithOverviewMode(true); webSetting.setAppCacheEnabled(true); // webSetting.setDatabaseEnabled(true); webSetting.setDomStorageEnabled(true); webSetting.setGeolocationEnabled(true); webSetting.setAppCacheMaxSize(Long.MAX_VALUE); // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY); webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND); // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH); webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE); // this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension // settings 的设计 }
Example 3
Source File: WrapperWebView.java From AndroidHybridLib with Apache License 2.0 | 6 votes |
private void initWebViewSettings() { WebSettings ws = mWebView.getSettings(); ws.setDefaultTextEncodingName("utf-8"); ws.setJavaScriptEnabled(true); ws.setPluginsEnabled(true); ws.setDomStorageEnabled(true); ws.setRenderPriority(com.tencent.smtt.sdk.WebSettings.RenderPriority.HIGH); ws.setAllowFileAccess(true); ws.setAllowContentAccess(true); ws.setAppCacheEnabled(false); ws.setCacheMode(com.tencent.smtt.sdk.WebSettings.LOAD_NO_CACHE); ws.setSaveFormData(true); ws.setJavaScriptCanOpenWindowsAutomatically(true); ws.setLoadsImagesAutomatically(true); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ws.setAllowFileAccessFromFileURLs(true); ws.setAllowUniversalAccessFromFileURLs(true); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { mWebView.setWebContentsDebuggingEnabled(true); } }
Example 4
Source File: X5WebView.java From Readhub with Apache License 2.0 | 6 votes |
private void initWebViewSettings() { WebSettings webSetting = this.getSettings(); webSetting.setJavaScriptEnabled(true); webSetting.setJavaScriptCanOpenWindowsAutomatically(true); webSetting.setAllowFileAccess(true); webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); webSetting.setSupportZoom(false); webSetting.setBuiltInZoomControls(false); webSetting.setUseWideViewPort(true); webSetting.setSupportMultipleWindows(true); webSetting.setAppCacheEnabled(true); webSetting.setDomStorageEnabled(true); webSetting.setGeolocationEnabled(true); webSetting.setAppCacheMaxSize(Long.MAX_VALUE); webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND); webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE); }
Example 5
Source File: X5WebView.java From FastAndroid with Apache License 2.0 | 6 votes |
@SuppressLint("SetJavaScriptEnabled") private void initWebViewSettings() { WebSettings webSetting = this.getSettings(); webSetting.setJavaScriptEnabled(true); webSetting.setJavaScriptCanOpenWindowsAutomatically(true); webSetting.setAllowFileAccess(true); webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); webSetting.setSupportZoom(true); webSetting.setBuiltInZoomControls(true); webSetting.setUseWideViewPort(true); webSetting.setSupportMultipleWindows(true); // webSetting.setLoadWithOverviewMode(true); webSetting.setAppCacheEnabled(true); // webSetting.setDatabaseEnabled(true); webSetting.setDomStorageEnabled(true); webSetting.setGeolocationEnabled(true); webSetting.setAppCacheMaxSize(Long.MAX_VALUE); // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY); webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND); // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH); webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE); // this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension // settings 的设计 }
Example 6
Source File: X5WebView.java From CacheWebView with MIT License | 6 votes |
private void initWebViewSettings() { WebSettings webSetting = this.getSettings(); webSetting.setJavaScriptEnabled(true); webSetting.setJavaScriptCanOpenWindowsAutomatically(true); webSetting.setAllowFileAccess(true); webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); webSetting.setSupportZoom(true); webSetting.setBuiltInZoomControls(true); webSetting.setUseWideViewPort(true); webSetting.setSupportMultipleWindows(true); // webSetting.setLoadWithOverviewMode(true); webSetting.setAppCacheEnabled(true); // webSetting.setDatabaseEnabled(true); webSetting.setDomStorageEnabled(true); webSetting.setGeolocationEnabled(true); webSetting.setAppCacheMaxSize(Long.MAX_VALUE); // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY); webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND); // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH); webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE); // this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension // settings 的设计 }
Example 7
Source File: WebViewFragment.java From Dainty with Apache License 2.0 | 5 votes |
@SuppressLint("SetJavaScriptEnabled") private void setSettings(WebSettings setting) { //noinspection deprecation setting.setJavaScriptEnabled(true); setting.setJavaScriptCanOpenWindowsAutomatically(true); setting.setAllowFileAccess(true); setting.setSupportZoom(true); setting.setBuiltInZoomControls(true); //允许放大缩小 setting.setDisplayZoomControls(false); //去掉放大缩小框 setting.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); setting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); setting.setSupportMultipleWindows(false); setting.setGeolocationEnabled(true); //允许启用地理定位 setting.setGeolocationDatabasePath(getActivity().getDir("geolocation", 0).getPath()); setting.setSaveFormData(true); //支持保存自动填充的表单数据 setting.setDomStorageEnabled(true); //支持DOM缓存 setting.setDatabaseEnabled(true); setting.setAppCacheEnabled(true); setting.setAppCacheMaxSize(Long.MAX_VALUE); setting.setAppCachePath(getActivity().getDir("dainty_cache", 0).getPath()); // 全屏显示 setting.setUseWideViewPort(true); setting.setTextZoom(Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(getContext()).getString("text_size", "100"))); }
Example 8
Source File: WebviewActivity.java From AndroidFrame with Apache License 2.0 | 4 votes |
private void initWebview() { mWebView = findViewById(R.id.webview); mBridge = new WebViewJavascriptBridge(this, sHandler, mWebView); mWebView.addJavascriptInterface(mBridge, "AndroidWebViewJavascriptBridge"); WebSettings webSetting = mWebView.getSettings(); webSetting.setJavaScriptEnabled(true); webSetting.setJavaScriptCanOpenWindowsAutomatically(true); webSetting.setAllowFileAccess(true); webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); webSetting.setSupportZoom(true); webSetting.setBuiltInZoomControls(true); webSetting.setUseWideViewPort(true); webSetting.setSupportMultipleWindows(true); // webSetting.setLoadWithOverviewMode(true); webSetting.setAppCacheEnabled(true); // webSetting.setDatabaseEnabled(true); webSetting.setDomStorageEnabled(true); webSetting.setGeolocationEnabled(true); webSetting.setAppCacheMaxSize(Long.MAX_VALUE); // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY); webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND); // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH); webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE); String userAgent = webSetting.getUserAgentString() + " " + AGENG_STR + AGENG_STR_SUFFIX + "/" + getVersionName() + "/QD" + getQudaoName() + "/"; webSetting.setUserAgentString(userAgent); mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView webView, String s) { InputStream fs = WebviewActivity.this.getResources().openRawResource( R.raw.jsbridge_init); String jsbridgeInitScript = getLocalText(fs); String js1 = "javascript:var evtAndroidJSB = document.createEvent('Event');" + "evtAndroidJSB.initEvent('AndroidWebViewJavascriptBridgeReady', false, false); " + "document.dispatchEvent(evtAndroidJSB);"; String js2 = "javascript: " + jsbridgeInitScript; if (android.os.Build.VERSION.SDK_INT <= 18) { mWebView.loadUrl(js1); mWebView.loadUrl(js2); } else { mWebView.evaluateJavascript(js1, null); mWebView.evaluateJavascript(js2, null); } super.onPageFinished(webView, s); } }); }
Example 9
Source File: x5_WebviewSelfAdaption.java From stynico with MIT License | 4 votes |
public void getWebviewAdaption(WebView webView) { WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setUseWideViewPort(true);//关键点 //启用地理定位 webSettings.setDomStorageEnabled(true); webSettings.setDatabaseEnabled((Boolean) SPUtils.get(context, "if_4", true));//数据库 webSettings.setGeolocationEnabled((Boolean) SPUtils.get(context, "if_2", true));//地理 webSettings.setUserAgentString("" + SPUtils.get(context, "if_7", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en-us) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3 XiaoMi/MiuiBrowser/8.9.4"));//UA webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); webSettings.setDisplayZoomControls(false); webSettings.setLoadsImagesAutomatically((Boolean) SPUtils.get(context, "if_5", true));//图片 webSettings.setJavaScriptEnabled((Boolean) SPUtils.get(context, "if_1", true)); // 设置支持javascript脚本 webSettings.setAllowFileAccess(true); // 允许访问文件 webSettings.setBuiltInZoomControls(true); // 设置显示缩放按钮 webSettings.setSupportZoom((Boolean) SPUtils.get(context, "if_3", false)); // 支持缩放 webSettings.setLoadWithOverviewMode(true); DisplayMetrics metrics = new DisplayMetrics(); //getWindowManager().getDefaultDisplay().getMetrics(metrics); int mDensity = metrics.densityDpi; // Log.d("maomao", "densityDpi = " + mDensity); if (mDensity == 240) { webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR); } else if (mDensity == 160) { webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM); } else if (mDensity == 120) { webSettings.setDefaultZoom(WebSettings.ZoomDensity.CLOSE); } else if (mDensity == DisplayMetrics.DENSITY_XHIGH) { webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR); } else if (mDensity == DisplayMetrics.DENSITY_TV) { webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR); } else { webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM); } webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); }
Example 10
Source File: CrazyDailyWebView.java From CrazyDaily with Apache License 2.0 | 4 votes |
@SuppressWarnings("all") private void init(Context context) { WebSettings setttings = getSettings(); setttings.setJavaScriptEnabled(true);//打开js setttings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);//设置布局 setttings.setDomStorageEnabled(true);//打开Dom Storage setttings.setDatabaseEnabled(true);//打开Database setttings.setAppCacheEnabled(true);//打开App Cache setttings.setAppCacheMaxSize(Long.MAX_VALUE); File cacheDir = new File(context.getExternalCacheDir(), CacheConstant.CACHE_DIR_WEB); if (!cacheDir.exists()) { cacheDir.mkdirs(); } setttings.setAppCachePath(cacheDir.getAbsolutePath());//设置App Cache缓存目录 setttings.setSupportMultipleWindows(false);//不支持多窗口 setttings.setJavaScriptCanOpenWindowsAutomatically(true);//支持js打开新窗口 setttings.setAllowFileAccess(true);//启用WebView访问文件数据 setttings.setSupportZoom(true);//支持缩放 setttings.setDisplayZoomControls(false);//隐藏webview缩放按钮 setttings.setBuiltInZoomControls(true);//支持手势缩放 setttings.setLoadWithOverviewMode(true);//缩放至屏幕大小 setttings.setUseWideViewPort(true);//调整屏幕自适应 setttings.setDefaultTextEncodingName("utf-8");//设置编码格式为utf-8 setttings.setLoadsImagesAutomatically(true);//支持自动加载图片 setttings.setSavePassword(false);//禁止密码保存在本地 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // https中支持访问http setttings.setMixedContentMode(android.webkit.WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // 支持第三方的cookie同步 CookieManager.getInstance().setAcceptThirdPartyCookies(this, true); } String ua = setttings.getUserAgentString(); setttings.setUserAgentString(String.format("%s CrazyDaily %s", ua, DeviceUtil.getVersionName()));//重置ua setWebViewClient(new CrazyDailyWebViewClient()); setWebChromeClient(new CrazyDailyWebChromeClient()); setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) { if (mDownloadCallback != null) { mDownloadCallback.onDownload(url, contentLength); } } }); }