您好,登錄后才能下訂單哦!
這期內容當中小編將會給大家帶來有關webview中iframe事件不可用如何解決,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
最近做Android的Webview開發,使用iframe中嵌入了很多頁面,嵌入的頁面卻不可用,最后發現是
webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return super.shouldOverrideUrlLoading(view, url); }
不要覆寫
shouldOverrideUrlLoading
這個方法,覆寫這個方法會攔截ifame中的事件。
補充知識:Android 原生WebView訪問使用iFrame網頁問題(頁面找不到了)
問題:
項目使用原生WebView訪問使用了iFrame的網頁出現的問題,列表頁使用iFrame跳轉到淘寶客的地址,單獨訪問淘寶客地址是能夠打開。但列表頁跳轉過去總是提示“頁面找不到了”,嘗試很多方法,最終發現是WebView對第三方Cookie支持的問題。
解決:
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true);
完整配置:
mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); } @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); super.onReceivedSslError(view, handler, error); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return super.shouldOverrideUrlLoading(view, url); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { return super.shouldInterceptRequest(view, request); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if (null != title && null != view && TextUtils.isEmpty(mTitle)) title.setText(view.getTitle()); } }); mWebView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView webView, int i) { super.onProgressChanged(webView, i); } @Override public boolean onJsConfirm(WebView view, String url, String message, android.webkit.JsResult result) { return super.onJsConfirm(view, url, message, result); } @Override public void onShowCustomView(View view, CustomViewCallback callback) { super.onShowCustomView(view, callback); } @Override public void onHideCustomView() { } @Override public boolean onShowFileChooser(WebView webView, android.webkit.ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { return super.onShowFileChooser(webView, filePathCallback, fileChooserParams); } @Override public boolean onJsAlert(WebView view, String url, String message, android.webkit.JsResult result) { return super.onJsAlert(view, url, message, result); } @Override public void onReceivedTitle(WebView view, String title) { super.onReceivedTitle(view, title); } } ); WebSettings mWebSettings = mWebView.getSettings(); mWebSettings.setAllowFileAccess(true); mWebSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); mWebSettings.setSupportZoom(true); mWebSettings.setBuiltInZoomControls(true); mWebSettings.setUseWideViewPort(true); mWebSettings.setSupportMultipleWindows(false); mWebSettings.setAppCacheEnabled(true); mWebSettings.setDomStorageEnabled(true); mWebSettings.setJavaScriptEnabled(true); mWebSettings.setGeolocationEnabled(true); mWebSettings.setAppCacheMaxSize(Long.MAX_VALUE); mWebSettings.setAppCachePath(getDir("appcache", 0).getPath()); mWebSettings.setDatabasePath(getDir("databases", 0).getPath()); mWebSettings.setGeolocationDatabasePath(getDir("geolocation", 0) .getPath()); mWebSettings.setPluginState(WebSettings.PluginState.ON_DEMAND); mWebSettings.setLoadWithOverviewMode(true); mWebSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); String mUserAgent = mWebSettings.getUserAgentString(); mWebSettings.setUserAgentString(mUserAgent + " App/AppName"); syncCookie(); mWebSettings.setUseWideViewPort(true); mWebSettings.setLoadWithOverviewMode(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { mWebSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); } else { mWebSettings.setCacheMode(WebSettings.LOAD_DEFAULT); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mWebSettings.setDisplayZoomControls(false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { mWebSettings.setLoadsImagesAutomatically(true); } else { mWebSettings.setLoadsImagesAutomatically(false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mWebSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true); mWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY); mWebView.setHorizontalScrollBarEnabled(false); mWebView.setHorizontalFadingEdgeEnabled(false); mWebView.setVerticalFadingEdgeEnabled(false); mWebView.requestFocus(); private void syncCookie() { CookieSyncManager.createInstance(this); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); CookieSyncManager.getInstance().sync(); }
上述就是小編為大家分享的webview中iframe事件不可用如何解決了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。