【问题标题】:jQueryMobile+PhoneGap+iOS 11: Blocked attempt to use history.replaceState() to change session history URLjQueryMobile+PhoneGap+iOS 11:阻止尝试使用 history.replaceState() 更改会话历史 URL
【发布时间】:2018-09-08 15:01:37
【问题描述】:

从 iPhone OS 11.3 开始,我的应用因以下错误而损坏:

SecurityError: Blocked attempt to use history.replaceState() to change session history URL from file:///var/containers/Bundle/Application/E73A3E4A-D961-4943-BAA3-7845E755F6A0/myplaceonline.app/www/index.html#/?phonegap=true to https://myplaceonline.com/?phonegap=true. Protocols, domains, ports, usernames, and passwords must match.
url:
file:///var/containers/Bundle/Application/E73A3E4A-D961-4943-BAA3-7845E755F6A0/myplaceonline.app/www/js/jquery.mobile-1.4.5.min.js
line #: 3 (31672)

我一直这样做的方式(这继续适用于 Android):

  1. PhoneGap appindex.html page 中加载 JQM。
  2. 附加了一个 JQM mobileinit 事件处理程序,它注册了一个最终调用 loadHomepagepageloaded 事件处理程序。
  3. loadHomepage 将$.mobile.path.documentBasebase 标签的href 属性设置到我的远程服务器(https://myplaceonline.com/)并调用$.mobile.pageContainer.pagecontainer("change", "/", { allowSamePageTransition: true, transition: 'none', reloadPage: true, changeHash: true }); 来加载远程主页。
  4. 这最终驱使 JQM 调用 replaceState 失败并出现安全错误: replaceState@[native code] squash@file:///var/containers/Bundle/Application/E73A3E4A-D961-4943-BAA3-7845E755F6A0/myplaceonline.app/www/js/jquery.mobile-1.4.5.min.js:3:31672 go@file:///var/containers/Bundle/Application/E73A3E4A-D961-4943-BAA3-7845E755F6A0/myplaceonline.app/www/js/jquery.mobile-1.4.5.min.js:4:322 navigate@file:///var/containers/Bundle/Application/E73A3E4A-D961-4943-BAA3-7845E755F6A0/myplaceonline.app/www/js/jquery.mobile-1.4.5.min.js:4:1598

以上所有内容的目的是让我不会离开file:///,因为如果我这样做,我将无法通过PhoneGap 访问所有本机电话JS API。这适用于旧版本的 iOS,并继续适用于 Android。

有什么替代方法可以绕过新版本 iOS 上更严格的安全性吗?或者,我看到像 https://github.com/jquery/jquery-mobile/issues/5465 这样的问题,它建议了一种禁用历史记录的方法,我想知道这是否是另一种解决方法,我会失去什么?

【问题讨论】:

    标签: jquery-mobile phonegap


    【解决方案1】:

    将以下代码添加到 mobileinit 处理程序可解决此问题:

    $.mobile.hashListeningEnabled = false;
    $.mobile.pushStateEnabled = false;
    $.mobile.changePage.defaults.changeHash = false;
    

    【讨论】:

      猜你喜欢
      • 2018-04-19
      • 1970-01-01
      • 1970-01-01
      • 2012-02-10
      • 1970-01-01
      • 2010-10-23
      • 2018-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多