应用程序加载到cordova

应用程序加载到cordova

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

问题描述

限时删除!!

我们正在尝试创建一个相对较薄的cordova 应用程序以部署到Windows Phone 8.1 平台它从远程服务器将一个 javascript 应用程序加载到其主 webView 中,但还保持对cordova/phonegap插件的访问.我们已经在 Android 上成功地做到了这一点(见本文底部).

We are attempting to create a relatively thin cordova app to be deployed to a windows phone 8.1 platformwhich 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.

  • 访问c​​ordova 插件.
  • 设备离线时的持久性.
  • 数据在应用中的持久性,尤其是在设备电源循环时.我们打算为此使用 indexDb.

这可能吗?如果可能,怎么办?

Is this possible and if so how?

window.location = remoteUrl ;

导致在系统浏览器中打开 remoteUrl.这不是我们所需要的.

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

windows 平台的 inapp 浏览器与cordova wiki 中描述.这表明

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

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

将在 Cordova WebView 中打开 URL.这不会发生.

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

我们可以手动创建一个 web view 并将其指向远程应用

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);

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

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

也不确定 webview 的沙箱化程度以及缓存数据之间的持久性执行 Windows 商店应用程序.

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

包括 inappBrowser 插件.

including the inappBrowser plugin.

配置文件

<access origin="*" />

在 Android Play 商店应用程序中,我们这样做:

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>

并将cordova.js、cordova_plugins.js文件和plugins目录复制到服务器来自cordova项目platformsandroidassetswww目录运行后

and copying to the server the cordova.js, cordova_plugins.js files and the plugins directoryfrom the cordova projects platformsandroidassetswww direcoryafter running

cordova build android

相关文档.

cordova 4.0.0 Cordova 主要文档

推荐答案

难道你不能在 webView 加载后尝试创建一个脚本元素吗?

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

尝试设置此代码:

    `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);`

关于函数onDeviceReady".

on the function "onDeviceReady".

来源:document.createElement("script") 同步

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

1403页,肝出来的..

09-07 01:19