gpt4 book ai didi

javascript - cordova window.location.href 行为错误

转载 作者:行者123 更新时间:2023-12-02 15:58:37 25 4
gpt4 key购买 nike

在我的 assets/www/index.html 中,我尝试在/data/data/files/xyz/index.html 使用以下 javascript 命令:

window.location.href = cordova.file.dataDirectory + "xyz/index.html";

../xyz/index.html 中,它还包含存在于同一 xyz 目录中的 cordova.js:

  <script type="text/javascript" src="cordova.js"></script>  

可以加载index.html,但在catlog中显示如下错误

W/CordovaWebViewImpl﹕ Blocked (possibly sub-frame) navigation to non-allowed URL: gap://ready

我的方法有问题吗?使用window.location.href在数据文件夹中打开另一个cordova应用程序是否错误?

编辑:我已经找到了根本原因,那就是/data/data/files/xyz/cordova.js 中的 cordova.js 与 asset 文件夹中的版本不同。在我复制相同的cordova js版本后,它可以加载而不会出现错误警告。谢谢。

最佳答案

您不需要使用“cordova.file.datadirectory”。仅当您使用文件插件访问数据文件时才会出现这种情况,例如保存游戏中的高分或关卡数据。您不使用该插件将页面加载/卸载到当前 Web View 中。

您希望所有 HTML 文件都位于与“index.html”相同的文件夹分支中。假设目录结构如下:

/ index.html      <!---- this is your current index.html

/ page2.html

/ js / index.js

/ xyz /index.html

您所要做的就是window.location='xyz/index.html'。不过,如果您正在为 iOS 进行开发,我强烈建议您不要替换整个页面。这几乎是你的应用程序被拒绝的一种有保证的方式。尝试使用“Framework7”之类的框架通过 AJAX 加载页面。

注意:您只能查看 Web View 中的文件,这些文件与初始 index.html 位于同一文件夹或其子文件夹中。

编辑:您想要加载另一个 Cordova Webview 应用程序。我建议仍然将其作为初始“index.html”文件夹的子文件夹。但是,您也许可以编写插件或自定义平台本身来访问其他文件。然而,这超出了这个问题的范围!

关于javascript - cordova window.location.href 行为错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31383284/

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