9

We are attempting to create a relatively thin cordova app to be deployed to a windows phone 8.1 platform which loads a javascript application into its main webView from a remote server, but also maintain access to the cordova/phonegap plugins. We have successfully done this in Android (see bottom of this post).

The remote application requires the following features.

  • access to the cordova plugins.
  • persistence when the device is off-line.
  • persistence of data in the app, in particular when the devices' power is cycled. We intend to use indexDb for this.

Is this possible and if so how?

Current state of play in Windows Phone 8.1

window.location = remoteUrl ;

causes the remoteUrl to be opened in the system browser. This is not what we require.

The inapp browser for the windows platform apears to slightly differently than described in the cordova wiki. It suggests that

window.open('http://whitelisted-url.com', '_self');  

will open the URL in the Cordova WebView. This does not happen.

We can create a web view by hand and point it at the remote app

var wv = dodument.createElement('x-ms-webview');
wv.style.width = "100%";
wv.style.height = "100%";
wv.navigate(remoteUrl);
document.body.appendChild(wv);

This however does not allow us access to the cordova plugins, even if the server serves the cordova.js files as part of the downloaded application.

Also not sure how sand boxed the webview is and how persistent the cached data is between executions of the windows store app.

Our Android Soulution

including the inappBrowser plugin.

config.xml

<access origin="*" />

In the Android play store application we do:

function launchRemote()
{
   window.open(remoteUrl,'_self');
}
document.addEventListener('deviceready', launchRemote, false);

The remote served application launch page includes the entry

<script type="text/javascript" src="cordova.js"></script>

and copying to the server the cordova.js, cordova_plugins.js files and the plugins directory from the cordova projects platforms\android\assets\www direcory after running

cordova build android

Releated documentation.

cordova 4.0.0 Cordova main docs

  • Try to use [ManifoldJS](http://manifoldjs.com/)' patch for Windows 8.1 using `window.external.notify` + `executeScriptAsync` as a JS-native bridge: https://github.com/daserge/manifold-win10-patch – daserge Nov 11 '15 at 14:27
  • @codeMonkey_1066 Did you find a solution to this issue on Windows 8.1 Phone/Laptop devices ? – Swaroop Nov 12 '15 at 11:16
  • Swaroop - how did you locally load the cordova.js file dynamically while serving the application remotely into the container? – paul Dec 14 '15 at 11:17
  • In my implementation i have a local **index.html** page with **cordova.js** embedded, then **onCordovaReady** i download via ajax some remote bundles, save it on filesystem and then inject it on DOM. Templates are served by remote, and script injected on startup in index page. – Frix33 Jan 04 '17 at 16:18

1 Answers1

0

Couldn't you just try to create a script element after the webView is loaded?

Try by setting up this code:

    `var script = document.createElement('script');
     script.onload = function() {
       alert("Script loaded and ready"); //callback function
     };
    script.src = "http://whatever.com/the/script.js";
    document.getElementsByTagName('head')[0].appendChild(script);`

on the function "onDeviceReady".

Source: document.createElement("script") synchronously

Kerlos Bekhit
  • 128
  • 1
  • 7