Search code examples
cordovawindows-phone-8visual-studio-cordova

Is it possible to load an external website inside a Cordova mobile app on Windows?


I have created the default Cordova application using

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

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>

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.

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.

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

Edit: 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?


Solution

  • 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/