Vic*_*tor 3 iframe android webview
我有一个受Javascript控制的本地网站,并将其加载到WebView中.该网站实际上是一个带有iframe的主页面,其内容根据用户输入而变化.主页面上有一个"下一步"按钮,用于运行一些javascript函数,并决定在iframe中加载哪个页面(通过document.getElement(...).src =)
在Android 2.1中,一切都运行良好 - 模拟和电话.webview正在正确加载所有页面.我在2.2手机上测试了它,每当我点击Next,页面(应该在iframe中加载)都会在默认浏览器中加载.
我定义了一个intent过滤器
<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>
Run Code Online (Sandbox Code Playgroud)
希望它将页面请求重定向到活动,但它不起作用.网址仍由浏览器加载.
使用shouldOverredeUrlLoading不能很好地工作,因为加载的链接是内部框架之一.我尝试加载javascript代码,将该url设置为iframe的src,但是没有用.
奇怪的是,这只发生在2.2手机上.在2.2模拟器中,它工作正常.
有任何想法吗?
Android 4.x似乎表现如下:
shouldOverrideUrlLoading 仅在整个页面即将更改时调用.
iframe只是页面的一部分.因此shouldOverrideUrlLoading不被称为.
压倒一切public WebResourceResponse shouldInterceptRequest(WebView view, String url)为我工作.
似乎没有适当的方法来阻止WebResourceResponse.您可以加载另一个URL,但:
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if( url.contains("myFancyUrl") ) {
// Do something
try {
return new WebResourceResponse("", "", new URL("http://myserver.com/myrootdocument.html").openStream());
} catch(Exception exception) {
Log.e( exception.toString() );
}
}
return super.shouldInterceptRequest(view, url);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16327 次 |
| 最近记录: |