Can Cordova's content be on a remote server?

207 Views Asked by At

My request seems pretty simple to me but I can't get it working.

I want to use Cordova as a mobile container for my already existing blog. I am using the windows platform for testing.

Here would my config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.testcordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>MyAPP</name>    
    <access origin="*" />    
    <content src="http://vmorneau.me/" />
</widget>

But it throwed me a APPX1404 error when building the app.

Then I putting back "index.html" in the content src and making a simple redirect (2 differents ways) but nothing happens. Just a blank page, as if nothing gets redirected.

Here is my index.html file:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>My Redirect</title>
    </head>
    <body>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript"> 
            document.addEventListener("deviceready", onDeviceReady, false);
            function onDeviceReady() {
                window.location.href="http://vmorneau.me";             
                //window.open("http://vmorneau.me", '_blank');
            } </script>
    </body>
</html>
2

There are 2 best solutions below

1
On

In your index.html, add a script to handle "deviceready" event (which means your cordova lib is ready), and inside it, try the redirect.

1
On

I tried it and had the same problem. When I looked at console output, there's a timeout error shown. Not sure why. I think you've found a bug.

11-08 06:02:27.169: D/CordovaWebView(1420): >>> loadUrl(http://www.johnwargo.com)
11-08 06:02:27.169: D/PluginManager(1420): init()
11-08 06:02:27.189: D/CordovaWebView(1420): >>> loadUrlNow()
11-08 06:02:27.469: D/CordovaActivity(1420): Resuming the App
11-08 06:02:27.579: D/SoftKeyboardDetect(1420): Ignore this event
11-08 06:02:27.879: I/Choreographer(1420): Skipped 82 frames!  The application may be doing too much work on its main thread.
11-08 06:02:28.019: D/gralloc_goldfish(1420): Emulator without GPU emulation detected.
11-08 06:02:28.269: D/SoftKeyboardDetect(1420): Ignore this event
11-08 06:02:28.349: I/ActivityManager(378): Displayed com.johnwargo.test/.CordovaApp: +3s376ms
11-08 06:02:28.379: D/AndroidRuntime(1405): Shutting down VM
11-08 06:02:28.399: D/dalvikvm(1405): Debugger has detached; object registry had 1 entries
11-08 06:02:28.689: I/Choreographer(378): Skipped 40 frames!  The application may be doing too much work on its main thread.
11-08 06:02:29.519: D/CordovaWebViewClient(1420): onPageStarted(http://www.johnwargo.com/)
11-08 06:02:29.519: D/CordovaActivity(1420): onMessage(onPageStarted,http://www.johnwargo.com/)
11-08 06:02:43.129: D/ConnectivityService(378): Sampling interval elapsed, updating statistics ..
11-08 06:02:43.289: D/ConnectivityService(378): Done.
11-08 06:02:43.289: D/ConnectivityService(378): Setting timer for 720seconds
11-08 06:02:47.229: E/CordovaWebView(1420): CordovaWebView: TIMEOUT ERROR!
11-08 06:02:48.229: W/ProcessCpuTracker(378): Skipping unknown process pid 1484
11-08 06:03:00.489: D/dalvikvm(1420): GC_FOR_ALLOC freed 317K, 10% free 3711K/4108K, paused 265ms, total 266ms

Here's a sample app that works:

<!DOCTYPE html>
<html>

<head>
  <title>Redirect</title>
  <meta charset="utf-8" />
  <meta name="format-detection" content="telephone=no" />
  <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height" />
  <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
  <script type="text/javascript" charset="utf-8">
    function onBodyLoad() {
      console.log("body load");
      alert("Body Load");
      document.addEventListener("deviceready", onDeviceReady, false);
    }

    function onDeviceReady() {
      console.log("Entering onDeviceReady");
      window.open('http://www.johnwargo.com', '_blank');
    }
  </script>
</head>

<body onload="onBodyLoad()">
  <h1>Redirect</h1>
  <p>This is a sample Cordova application.</p>
</body>

</html>