Load external page on to Cordova/Phonegap application

22,560

Solution 1

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

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

OR by Inapp browser

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

go through the documentation

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

Hope this will helps you.

Solution 2

Unless I'm crazy, can't you just XHR the page and add it to the DOM? If using jQuery, just do it with $.get method.

syntax -

$.get(url, [data], [callback], [type])
Share:
22,560
candlejack
Author by

candlejack

I am and always I will be a studious. Have a nice day :)

Updated on March 16, 2020

Comments

  • candlejack
    candlejack about 4 years

    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.

    Thanks!

  • candlejack
    candlejack about 10 years
    Thanks Mr. Camden! But, can you show me an example of this, please?
  • bhantol
    bhantol about 8 years
    .load seems to be broken (not sure intentionally) in Cordova 6 on Windows