codeMonkey_1066
codeMonkey_1066

Reputation: 91

How to load a remote javascript app into a cordova windows phone 8.1 app and have it access cordova plugins

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.

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

Upvotes: 9

Views: 3432

Answers (1)

Kerlos Bekhit
Kerlos Bekhit

Reputation: 128

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

Upvotes: 0

Related Questions