gpt4 book ai didi

android - Android ICS 上的 WebView,android_assets 的 iframe 问题

转载 作者:IT王子 更新时间:2023-10-29 00:09:59 27 4
gpt4 key购买 nike

我的应用程序引擎在 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 作为标题注入(inject)任何加载的页面 -> 失败
  • 创建 iframe,设置 sandbox=same_origin,allow_scripts -> 失败

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

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

最佳答案

先生们,我在 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 - Android ICS 上的 WebView,android_assets 的 iframe 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9050949/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com