【问题标题】:WebView on Android ICS, iframe problems with android_assetsAndroid ICS 上的 WebView,android_assets 的 iframe 问题
【发布时间】:2012-02-21 11:37:28
【问题描述】:

我的应用程序引擎在 WebView 中运行。它跨越不同的 IFRAME。 主应用程序 html 和 iframe html 都在 android_assets 上。 在 Android 3.x 上没有任何问题。在 chrome 浏览器等上也一样。

如果我创建一个 IFRAME (createElement -> appendChild),那么 iframe 就会被创建。

当我在其中加载内容时 (iframe.src="url" iframe.contentWindow.location.href="url") ...它取代了主应用程序!! (而不是加载到 iframe 中)

已经试过了:

  • window.setTimeout 延迟加载...失败。
  • 在 webview 中,将 X-Frame-Options=SAME_ORIGIN 作为标题注入任何已加载的页面 -> 失败
  • 创建 iframe,设置 sandbox=same_origin,allow_scripts -> 失败

有人遇到类似问题吗?或者有人可以帮我找到有关 WebView ICS 错误与 Honeycomb 的文档吗?

还发现了许多其他奇怪的问题... ICS 真的有这么多问题吗? :S :S

【问题讨论】:

  • PhoneGap 有完全相同的问题,在以前版本的 Android 上一切正常
  • 我认为 ICS 将 Webkit 组件切换为移动 Chrome 源的组件。 (我注意到它现在使用 SPDY,而旧的 WebView 没有。)通过查看新源可能会发现该错误
  • 首先,ICS 中的 Web 发生了巨大的变化。其次,我遇到了一个问题,但不像你,我的游戏在所有设备上运行良好,除了那些运行 ICS 的设备。我解决了这个问题,但没有添加任何自定义框架布局。我认为您最好在 Google 上搜索他们对 ICS 所做的更改。然后你会找到解决方案。
  • 我之前也遇到过类似的bug,这里有个issue相关code.google.com/p/android/issues/detail?id=23362

标签: android iframe webview android-4.0-ice-cream-sandwich android-assets


【解决方案1】:

先生们,我在 Android Ice Cream Sandwich (4.0.3) 中使用 Phonegap (Apache Cordova) 和 IFrame 时遇到了同样的问题。

为了解决这个问题,我不得不编辑 Apache Cordova 源代码。我更改了 org.apache.cordova.CordovaWebViewClient.java 文件,并注释了这部分代码,并包含了最后一行(return false;)。

所以它现在看起来像这样:

    // All else
    //        else {
    //
    //            // If our app or file:, then load into a new Cordova webview container by starting a new instance of our activity.
    //            // Our app continues to run.  When BACK is pressed, our app is redisplayed.
    //            if (url.startsWith("file://") || url.indexOf(this.ctx.baseUrl) == 0 || ctx.isUrlWhiteListed(url)) {
    //                this.ctx.loadUrl(url);
    //            }
    //
    //            // If not our application, let default viewer handle
    //            else {
    //                try {
    //                    Intent intent = new Intent(Intent.ACTION_VIEW);
    //                    intent.setData(Uri.parse(url));
    //                    ctx.startActivity(intent);
    //                } catch (android.content.ActivityNotFoundException e) {
    //                    LOG.e(TAG, "Error loading url "+url, e);
    //                }
    //            }
    //        }
    //        return true;
    return false;

此问题仅发生在 Android ICS 上,但我更改了所有应用的代码。我还在做测试。

在我的分析中,似乎当您尝试在 iFrame 中加载页面时,ICS 上的 Android WebView 将其解释为新页面请求,并且它取代了主应用程序!!,或者换句话说,它在孔父窗口中打开请求的页面。

我没有修改其余代码。

我希望它有所帮助,就像它对我一样。

最好的问候。

亚历山大·阿尔梅达

【讨论】:

  • 我很晚才说非常感谢!停止了一段时间的android开发,但我很快将不得不面对这个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-28
  • 1970-01-01
  • 2012-07-19
  • 2011-12-20
相关资源
最近更新 更多