3

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 e.g. 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

RichiRoloff
  • 41
  • 1
  • 4
  • Have you tried this [solution](http://stackoverflow.com/questions/30151385/how-to-make-phonegap-window-location-href-not-launch-chrome-on-android) with `cordova-plugin-whitelist` and `` in your `config.xml` ? Note the `window.location.href` instead of `window.location` – Quentin Sep 01 '16 at 09:01
  • `cordova-plugin-whitelist` seems to be standard in phonegap package. Therefore, yes it is installed as i use the pure phonegap installation for this testing now. But your suggestion did not work. Instead I created a test.html and wrote `window.location.href = "test.html";` and ``. This worked so far as test.html was shown after device is ready.... so internal href work external (as e.g. https.//www.google.com) not? – RichiRoloff Sep 01 '16 at 10:35
  • Please, check your PhoneGap Desktop log. Or click on the server url and open in in a browser. Check your browser log. Do you have any errors? – Edward Oct 04 '16 at 01:13
  • Did you ever find a solution? I'm having the same issue. – Tim Tisdall Jun 16 '17 at 19:39

2 Answers2

2

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

Maui Doug
  • 108
  • 1
  • 9
0

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" />
4b0
  • 21,981
  • 30
  • 95
  • 142
Alejandro
  • 3
  • 1