Cordova应用程式(iOS)中的iframe history.back()问题 [英] iframe history.back() issues in Cordova app (iOS)

查看:913
本文介绍了Cordova应用程式(iOS)中的iframe history.back()问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Cordova开发Android和iOS的应用程序。

I am developing the application of Android and iOS by using Cordova.

页面结构如下。

- 第A页(不含iframe)

- 第B页iframe)

Page structure is as follows.
- Page A (w/o iframe)
- Page B (w/ iframe)

转换

1.页A - >页B(转发)

2.页A& - Page B(由history.back()退回)

Transitions
1. Page A --> Page B (forward)
2. Page A <-- Page B (backward by history.back())

iframe显示外部网页。

当返回A页/ o iframe)from Page B(w / iframe),我必须调用hisotory.back()两次。

然而,使用相同的javascript源构建Android应用程序只需要调用history.back 。

此外,当使用iOS的本机WebVIew(UIWebView)时,不会发生类似的问题。

iframe displays external web page.
When it goes back to Page A(w/o iframe) from Page B(w/ iframe), i have to call hisotory.back() twice.
However, Android app build by same javascript source only has to call history.back() once.
In addition, a similar problem does not occur when native WebVIew(UIWebView) of iOS is used.

这是Cordova(iOS)规格或错误吗?

有人遇到这个问题吗?

Is this a Cordova(iOS) spec or bug?
Did anyone experience this issue?

版本

Cordova 4.2(iOS平台3.8.0)

iOS 8.3

Versions
Cordova 4.2 (iOS Platform 3.8.0)
iOS 8.3

感谢。

推荐答案

首先,iOS中的iframe共享历史记录。
第二,iOS中的Cordova使用iframe作为JsToNativeBridge。

First, iframes in iOS share their history. Second, Cordova in iOS uses iframe as a JsToNativeBridge.

因此,在您的应用程序中,有两个iframe。
一个用于显示您的页面。
另一个用于JsToNativeBridge。 (此iframe已隐藏)

Therefore, in your application, there are two iframes. The one is used for showing your Page. the other is used for JsToNativeBridge. (This iframe is hidden)

history.back的功能会冲突这两个iframe。

The function of history.back conflicts these two iframes.

在deviceready事件之后,在任何插件工作之前,执行

After the deviceready event, before any plugin does work, execute that

var exec = cordova.require('cordova/exec');
exec.setJsToNativeBridgeMode(exec.jsToNativeModes.XHR_OPTIONAL_PAYLOAD);

注意一些插件使用addEventlistener来设置deviceready事件。如果您使用这种
插件,请尝试下一个解决方案。

Remark some plugins use addEventlistener for deviceready event. If you use such plugin, please try the next solution.

另一种解决方案是在iOS中修改cordova.js。

The other solution is modifying the cordova.js in iOS.

之前:

if (bridgeMode === undefined) {
    bridgeMode = jsToNativeModes.IFRAME_NAV;   
}

之后:

if (bridgeMode === undefined) {
    bridgeMode = jsToNativeModes.XHR_NO_PAYLOAD;
    // bridgeMode = jsToNativeModes.IFRAME_NAV;
}

这篇关于Cordova应用程式(iOS)中的iframe history.back()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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