简体   繁体   中英

phonegap window.location onDeviceReady not working

I am trying to put my mobile Website into PhoneGap to create a "native" app. Therefore I start googling and found that onDeviceReady window.location should solve this.

this solution was eg described here already: http://antonylees.blogspot.de/2013/02/launch-website-as-mobile-app-using.html

However following the Option 2 (which just consits of window.location) solution, it does not work. The alerts are shown but window.location not works, which means it does not show the new window location, but just the original phonegap loading screen. (alert of current page contains same message as alert after)

Any ideas?

this is the relevant code part of 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
},

this ist the relevant part of config.xml

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

Oh, I just installed the latest phonegap for windows, created a new project and just did changed index.js as can be seen above.

thx a lot

I started with the phonegap sample - https://github.com/phonegap/phonegap-start ,

changed the config.xml per your post

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

I changed the received event, in js/index.js to change the window.location

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

It seems to work in build.phonegap.com for IOS ad_hoc. I have not tried the build in the app store

Same problem for me. After a few days working around I, figure it out.

Adding this line to my config.xml

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM