【问题标题】:phonegap window.location onDeviceReady not workingphonegap window.location onDeviceReady 不工作
【发布时间】:2017-01-09 01:39:51
【问题描述】:

我正在尝试将我的移动网站放入 PhoneGap 以创建一个“本地”应用程序。因此我开始谷歌搜索,发现 onDeviceReady window.location 应该可以解决这个问题。

这个解决方案是例如这里已经描述过:http://antonylees.blogspot.de/2013/02/launch-website-as-mobile-app-using.html

但是按照选项 2(仅包含 window.location)解决方案,它不起作用。显示警报但 window.location 不起作用,这意味着它不显示新窗口位置,而只是显示原始 phonegap 加载屏幕。 (当前页面的警报包含与之后的警报相同的消息)

有什么想法吗?

这是 index.js 的相关代码部分

onDeviceReady: function() {
    app.receivedEvent('deviceready');
    alert(window.location.href);           //current page
    window.location = "https://www.google.com";
    alert(window.location.href);          //page after location set
},

这是 config.xml 的相关部分

  <access origin="*"/>
  <allow-navigation href="*" />

哦,我刚刚为 windows 安装了最新的 phonegap,创建了一个新项目,并且刚刚更改了 index.js,如上所示。

非常感谢

【问题讨论】:

  • 您是否在您的config.xml 中使用cordova-plugin-whitelist&lt;allow-navigation href="https://example.com/*" /&gt; 尝试过这个solution?注意window.location.href 而不是window.location
  • cordova-plugin-whitelist 似乎是 phonegap 包中的标准配置。因此,是的,它已安装,因为我现在使用纯 phonegap 安装进行此测试。但是你的建议没有奏效。相反,我创建了一个 test.html 并写了 window.location.href = "test.html";&lt;allow-navigation href="*" /&gt;。就在设备准备好后显示 test.html 而言,这是有效的......所以内部 href 可以在外部工作(例如 https.//www.google.com)不是吗?
  • 请检查您的 PhoneGap 桌面日志。或单击服务器 url 并在浏览器中打开。检查您的浏览器日志。你有什么错误吗?
  • 您找到解决方案了吗?我也有同样的问题。

标签: javascript cordova window.location phonegap-desktop-app


【解决方案1】:

我从 phonegap 示例开始 - https://github.com/phonegap/phonegap-start

根据您的帖子更改了 config.xml

<access origin="*"/> <allow-navigation href="*" />

我改变了接收到的事件,在js/index.js中改变window.location

// Update DOM on a Received Event
receivedEvent: function(id) {
   window.location =  "http://your.domain.com";
}

它似乎适用于 IOS ad_hoc 的 build.phonegap.com。我没有在应用商店尝试过构建

【讨论】:

    【解决方案2】:

    对我来说同样的问题。在我周围工作了几天后,弄清楚了。

    将此行添加到我的 config.xml

    <plugin name="cordova-plugin-whitelist" spec="1" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-05
      • 1970-01-01
      • 1970-01-01
      • 2011-08-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多