Venkat Papana
Venkat Papana

Reputation: 4937

phonegap: loading remote html

I'm searching for a way to load remote html's in phonegap android app. I'm using super.loadUrl("file:///android_asset/www/hello.html"); but how to load remote html page?

Upvotes: 3

Views: 4560

Answers (1)

Mayur Birari
Mayur Birari

Reputation: 5835

it's very simple Venkat,

just load required html page with the http request,

super.loadUrl("http://www.test.com/test1.html");

or you can load local html file like you did

super.loadUrl("file:///android_asset/www/hello.html");

and in hello.html used window.location in onLoad() javascript function to load external html page.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <!-- Change this if you want to allow scaling -->
    <meta name="viewport" content="width=default-width; user-scalable=no" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <title>LoadUrl
    <script type="text/javascript" charset="utf-8">
    function onBodyLoad()
    {
        document.addEventListener("deviceready",onDeviceReady,false);
    }
    /* When this function is called, PhoneGap has been initialized and is ready to roll */
    function onDeviceReady()
    {
    // do your thing!
      window.location="http://170.60.26.20:8099/Sencha/Html/index.html";
    }
    </script>
  </head>
  <body onload="onBodyLoad()">   
  </body>
</html>

Please make sure you set the internet permission in android manifest file.

Upvotes: 7

Related Questions