Back

WebView

You can create a control to display local or remote web pages in your App using the CreateWebView method of the app object:

 web = app.CreateWebView( width, height );

If you are loading remote web pages, then you might want to use the SetOnProgress method to set the name of a callback function that you want called to report the progress of loading the page.

You can use the LoadUrl method to load an internal or external web page or the LoadHtml method to load text directly from within your App.

 web.LoadUrl( url );
 web.LoadHtml( html, baseFolder );

Note: Using a WebView can be a good way of displaying colored and formatted text areas in your App. If you set the BackColor to a transparent color you can show formatted text over a background image.

If you need to, you can use the Execute method to execute JavaScript code within the WebView.

 web.Execute( text );

Example - Remote

function OnStart()
{
  lay = app.CreateLayout( "linear", "VCenter,FillXY" );

   web = app.CreateWebView( 0.8, 0.8 );
   web.SetOnProgress( web_OnProgess );
   lay.AddChild( web );

   app.AddLayout( lay );

   app.ShowProgress("Loading...");
   web.LoadUrl( "http:///www.google.com" );
}

function web_OnProgess( progress )
{
   app.Debug( "progress = " + progress );
   if( progress==100 ) app.HideProgress();
}
  Copy   Copy All    Run   

Example - Local

function OnStart()
{
  lay = app.CreateLayout( "linear", "VCenter,FillXY" );

   web = app.CreateWebView( 0.8, 0.8 );
   web.SetBackColor( "#00000000" );
   lay.AddChild( web );

   app.AddLayout( lay );

   web.LoadUrl( "file:///Sys/Html/Page.htm" );
}

  Copy   Copy All    Run   

Example - Direct

function OnStart()
{
  lay = app.CreateLayout( "linear", "VCenter,FillXY" );

   web = app.CreateWebView( 0.8, 0.8 );
   web.SetBackColor( "#00000000" );
   lay.AddChild( web );

   app.AddLayout( lay );

   var html = "<html><head>";
   html += "<meta name='viewport' content='width=device-width'>";
   html += "</head><body>Hello World!<br>";
   html += "<img src='Img/Droid2.png'>";
   html += "</body></html>";
   web.LoadHtml( html, "file:///Sys/" );
}

  Copy   Copy All    Run   

The following methods are avaiable on the WebView object:

 SetVisibility( visibility )
 GetVisibility()
 SetPadding( left, top, right, bottom )
 SetMargins( left, top, right, bottom )
 SetBackground( imageFile, options )
 SetBackColor( colorCode )
 SetBackGradient( color1, color2, color3 )
 SetBackGradientRadial( x, y, r, color1, color2, color3 )
 SetPosition( left, top, width, height )
 SetSize( width, height )
 GetWidth()
 GetHeight()
 SetOnProgress( callback )
 LoadHtml( html, baseFolder )
 LoadUrl( url )
 Back()
 Forward()
 Execute( text )