将外部页面加载到Cordova / Phonegap应用程序

将外部页面加载到Cordova / Phonegap应用程序

问题描述:

我有一个Cordova / Phonegap应用程序。开始检查互联网连接。
其实应用程序执行本地文件,但我想,当有互联网连接,我的应用程序加载外部网页(这是我的应用程序的在线版本)。

I have a Cordova/Phonegap application. that on start checks the internet connection. Actually the app executes local files, but I would, that when there is internet connection, my app loads an external webpage (which is the online version of my app).

我如何实现这一点?我已经有脚本检查互联网连接。

How can I achieve this? I have already the script for check internet connection.

谢谢!

p>您可以使用Jquery load()或Ajax或InApp浏览器将外部网页加载到应用程序。

You can Load an external page to the app using Jquery load() or by Ajax or by InApp browser.

如果要将外部网页显示到div ,您可以通过load()或ajax调用来实现

If you want to show the external page to a div, you can do it by load() or by ajax call

HTML

<div id="Load"></div>
<hr/>
<div id="ajax"></div>

JS:

/*Using Jquery Load()*/
$('#Load').load('http://www.google.co.in');

/*Using ajax*/
$.ajax({
  dataType:'html',
  url:'http://www.google.co.in',
  success:function(data) {
    $('#ajax').html($(data).children());   
  }
});

或者 Inapp browser

OR by Inapp browser

 window.open('http://www.google.co.in','_self');

浏览 文档

go through the documentation

在使用inappbrowser之前,必须将插件安装到项目中
通过commanline添加inappbrowser到项目

Before using inappbrowser you must install the plugin to your project To add inappbrowser to project by commanline

$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git

希望这将有助于你。