是否可以在Windows的Cordova移动应用程序中加载外部网站? [英] Is it possible to load an external website inside a Cordova mobile app on Windows?

查看:106
本文介绍了是否可以在Windows的Cordova移动应用程序中加载外部网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用创建了默认的Cordova应用程序

I have created the default Cordova application using

cordova create ...
cordova platform add android
cordova platform add windows

在index.html中,我添加了一些指向外部网站的链接(不是本地安装的html文件):

In the index.html, I added some links to an external websites (not locally installed html files):

<a href="http://www.example.com">External Website</a>
<a href="http://dev2.prsx.net">External Intranet Site</a>

在Android中,点击这些链接将在Cordova容器中拉出该站点.这是我想要的行为.在Windows上,它将在外部Internet Explorer浏览器中打开example.com页面.当我单击dev2.prsx.net链接时,没有任何反应.从字面上看,什么也没有发生.它不会打开浏览器,也不会以任何方式改变屏幕,Visual Studio中没有错误消息.

In Android, tapping these links pulls up the site within the Cordova container. This is the behavior I want. On Windows, it pulls up the example.com page in the external Internet Explorer browser. Nothing happens when I click on the dev2.prsx.net link. Literally, nothing happens. It doesn't open a browser, it doesn't change the screen in any way, there is no error message in Visual Studio.

应该注意,我要将Intranet站点加载到Cordova容器中,因为外部站点还将包括cordova.js文件和我将使用的插件.这适用于Android.但是现在,我只想知道我是否可以在Windows上加载外部页面.

It should be noted that I want to load the intranet site in the Cordova container because the external site will also include the cordova.js file and plugins that I will use. This works on Android. But right now, I just want to know if I can load external pages on Windows.

是否可以在Windows平台上复制在Android中看到的行为?

Is it possible to replicate the behavior seen in Android on the Windows platform?

我进入了package.windows.appxmanifest文件,并查看了功能"选项卡.我打开了专用网络功能,现在我的Intranet站点确实已加载到外部IE浏览器中.所以现在我唯一的问题是,我可以在Cordova容器中加载网站吗?

I went in to the package.windows.appxmanifest file and looked at the Capabilities tab. I turned on the Private Networks Capability and now my intranet site does load in the external IE browser. So now my only question is, can I make the site load in the Cordova container?

推荐答案

我发现唯一可行的方法是创建一个iFrame或x-ms-webview来加载远程内容.这实际上是InAppBrowser所做的你.但是,我的问题是我希望远程内容能够调用Cordova API.为此,我在Web视图和有权访问API的父本地页面之间来回使用传递消息.我使用Webview上的MSWebViewScriptNotify事件和如本文中所述的invokeScriptAsync方法执行此操作:

The only way I have found that works is by creating an iFrame or x-ms-webview to load the remote content in. This is essentially what InAppBrowser does for you. However, my problem was that I want the remote content to be able to call Cordova APIs. To accomplish this, I use pass messages back and forth between the webview and the parent local page that has access to APIs. I do this with the MSWebViewScriptNotify event on the webview and the invokeScriptAsync method as described in this article: http://blogs.windows.com/buildingapps/2013/10/01/blending-apps-and-sites-with-the-html-x-ms-webview/

这篇关于是否可以在Windows的Cordova移动应用程序中加载外部网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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