如何将远程JavaScript应用程序加载到cordova windows phone 8.1应用程序中并让它访问cordova插件 [英] How to load a remote javascript app into a cordova windows phone 8.1 app and have it access cordova plugins

查看:129
本文介绍了如何将远程JavaScript应用程序加载到cordova windows phone 8.1应用程序中并让它访问cordova插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试创建一个相对较薄的cordova应用程序,以部署到Windows Phone 8.1平台
,该应用程序从远程服务器将JavaScript应用程序加载到其主要webView中,同时还可以访问cordova / phonegap插件。
我们已经在Android中成功完成了这个任务(见本文的底部)。



远程应用程序需要以下功能。




  • 访问c​​ordova插件。


  • 当设备脱机时的持久性。 >应用程序中的数据持久性,特别是当设备的电源循环时。我们打算为此使用indexDb。


这是可能的吗?如果是这样?



Windows Phone 8.1中的当前状态



  window.location = remoteUrl; 

导致remoteUrl在系统浏览器中打开。这不是我们要求的。

Windows平台的inapp浏览器与科尔多瓦维基。它表明,

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

将打开Cordova WebView中的URL。这不会发生。



我们可以手动创建网页视图,并将其指向远程应用程序。

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

然而,这并不允许我们访问cordova插件,即使服务器
服务cordova.js文件作为下载的应用程序的一部分。



还不确定如何沙盒装webview,以及如何持久缓存数据之间
执行包括inappBrowser插件。



我们的Android Soulution



config.xml

 < access origin =*/> 

在我们的Android Play商店应用程序中:

 函数launchRemote()
{
window.open(remoteUrl,'_ self');
}
document.addEventListener('deviceready',launchRemote,false);

远程服务的应用程序启动页面包含条目

 < script type =text / javascriptsrc =cordova.js>< / script> 

并复制到服务器cordova.js,cordova_plugins.js文件和插件目录
从cordova项目平台\roid \assets\www.root
跑完之后

  cordova build android 



相关文件。



cordova 4.0.0 科尔多瓦主文档

您可以在webView加载后创建脚本元素吗?



试着设置这个代码:

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

在函数onDeviceReady上。



来源:文档.createElement(" script")同步


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

解决方案

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

这篇关于如何将远程JavaScript应用程序加载到cordova windows phone 8.1应用程序中并让它访问cordova插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆