0

I have a web app, hosted in a phonegap application (i use phonegap build for this)

The setup is simple, but shouldn't really matter in this case. I'll tell you anyways because sometimes the devil is in the details, right? :)

The details

The phonegap app is really just the minimal setup with one single html. That html actually serves as a splashscreen - the background of HTML has an image. There is a meta refresh tag, set to redirect the page to an external url. I'll call it myurl.com from now.

The website at myurl.com is build using jquery mobile and angularjs. I use that adapter floating around to handle the problem with both frameworks wanting to manipulate the dom on page load. This is the domain the app is really hosted on and where the whole application is run.

The setup

One page has a link to an external page. That page has a bootload of javascript, showing some fancy stuff. If you click the link - your app takes you to that page. That is great! It actually works on all devices. On my desktop browser and android app, i simply hit the hardware (or browser) BACK button and i'm returned to my app at myurl.com. Iphone on the other hand doesn't have a back button :(

My first attempt is creating a landing page that has a back button/link and an iframe to host the fancy page. It works on desktop and android even though i get some exceptions/errors in the console. It doesn't load on iphone - i can only suspect security issues. I am told that what i'm trying to do with the iframe won't work which i think is true.

How do i deal with this? I actually tried the InAppBrowser like this:

var ref = window.open(url, 'random_string', 'location=yes'); 

And i checked my config.xml has this:

<preference name="stay-in-webview"            value="false" />

I also added this to my page:

<script stype="text/javascript" src="phonegap.js"></script> 

Leaving out the phonegap.js file since phonegap build promise to include the correct version.

It still opens the page in the same view/app without the possibility to go back - i get the excat same result as just opening the link the normal way.

Help me {insert jedi name here}, you're my only hope!

EDIT: I found the problem. The phonegap.js file is automaticly deployed ON the device so only the first index.html (with the meta refresh) actually links correctly. The pages on myurl.com is not linking to the file. I placed the phonegap.js on myurl.com and it's working. Only problem, the phonegap.js is different per device - meaning only the device i picked the phonegap.js from is working - the other devices break!

Anywhere i can link to the native apps files? i tried file:///{path}/phonegap.js but it doesn't work. I can see/guess the path, which is different per device, but for iphone its Payload{name}.app\www - it won't load from there though... i also tried

http://localhost/phonegap.js

but that doesn't work either.

Any ideas?

FINAL EDIT

I decided to go back to the drawing board and place all the html files on the device instead. I'll implement JSONP on my ajax api instead so i can let the API live on myurl.com and still access it from the phone. It's probably also the intended way to make a phonegap app - i just liked the other approach more...

Per Hornshøj-Schierbeck
  • 15,097
  • 21
  • 80
  • 101

1 Answers1

0

I actually just answered a question like this the other day. You can find it here. In short, see below:

  1. Ensure you have <script src="phonegap.js"></script> in each of your pages that wants to use the inappbrowser
  2. You should NOT need to include a plug-in tag in your config.xml. I am pretty sure that around 2.5 they included inappbrowser in the core build functionality.
  3. To open a link in the inappbrowser, use this javascript:

    function openURL(urlString){
        myURL = encodeURI(urlString);
        window.open(myURL, '_blank');
    }
    

    This will open the passed URL in the inappbrowser. If you change window.open(myURL, '_blank'); to window.open(myURL, '_system'); it will open the passed URL in the system browser.

  4. Finally, your item clicks look like this:

    <a href='#' onclick='openURL("http://www.urlyouwant")/>
    

Also, depending on the version of phonegap you are using, stayinwebview is depreciated.

***Based on your edit: Do not put phonegap.js in your project directory. When you upload it to build, it will include it in your project.

Community
  • 1
  • 1
Dom
  • 2,569
  • 1
  • 18
  • 28
  • Thanks, but i think i do need to deploy phonegap.js because it won't be deployed onto the myurl.com site because phonegap knows nothing about it, besides the link on the index.html, and myurl.com needs to reference it but won't know where to look for it. There is no CDN for phonegap.js right? – Per Hornshøj-Schierbeck Sep 13 '13 at 08:43