Android webView shouldOverrideUrlLoading for iframes [英] Android webView shouldOverrideUrlLoading for iframes

查看:777
本文介绍了Android webView shouldOverrideUrlLoading for iframes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个受Javascript控制的本地网站,并将其加载到WebView中。该网站实际上是一个带有iframe的主页面,其内容根据用户输入而变化。主页上有一个下一步按钮,用于运行一些javascript函数,并决定在iframe中加载哪个页面(通过document.getElement(...)。src =)

I have a local website that is Javascript controlled and am loading it in a WebView. The website is really one main page with an iframe whose content changes based on user input. There is a "Next" button on the main page that runs some javascript functions and decides which page to load in the iframe (via document.getElement(...).src = )

在Android 2.1中,一切都运行良好 - 模拟和手机。 webview正在正确加载所有页面。
我在2.2手机上测试了它,每当我点击Next,页面(应该在iframe中加载)都会在默认浏览器中加载。

In Android 2.1 things were working fine - simulated and on phone. The webview was loading all the pages properly. I tested it on a 2.2 phone and whenever I click Next the page (that should be loaded in the iframe) is loaded in the default browser.

I定义了一个意图过滤器

I defined an intent filter

   <intent-filter>
     <action android:name="android.intent.action.VIEW" />
     <category android:name="android.intent.category.DEFAULT" />
     <category android:name="android.intent.category.BROWSABLE" />
     <data
       android:scheme="file"
       android:host="*"
       android:pathPrefix="sdcard/Android/data/android.website/files/pages"
     />
    </intent-filter>

希望它将页面请求重定向到活动,但它不起作用。网址仍然由浏览器加载。

hoping that it would redirect the page requests to the activity, but it doesn't work. The url is still loaded by the browser.

使用shouldOverredeUrlLoading不能正常工作,因为加载的链接是内部框架之一。我尝试加载javascript代码,将该url设置为iframe的src,但无法正常工作。

Using shouldOverredeUrlLoading doesn't work well because the link that is loaded is the one of the internal frame. I tried loading instead javascript code that sets that url as the src of the iframe, but didn't work.

奇怪的是,这只发生在2.2手机上。在2.2模拟器中它工作正常。

It's weird that this only happens on the 2.2 phone. In a 2.2 emulator it works fine.

任何想法?

推荐答案

尝试向WebView提供您自己的 WebViewClient 。你应该覆盖 shouldOverrideUrlLoading(..) 并返回 false

Try providing your own WebViewClient to WebView. You should override shouldOverrideUrlLoading(..) and return false.

这篇关于Android webView shouldOverrideUrlLoading for iframes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆