大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这期内容当中小编将会给大家带来有关webview中iframe事件不可用如何解决,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
创新互联专注于企业全网营销推广、网站重做改版、漯河网站定制设计、自适应品牌网站建设、H5场景定制、成都商城网站开发、集团公司官网建设、外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为漯河等各大城市提供网站开发制作服务。
最近做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.ValueCallbackfilePathCallback, 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事件不可用如何解决了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。