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, options );
web.LoadHtml( html, baseFolder, options );
The supported options for LoadUrl and LoadHtml are: "allowzoom" (support zooming gestures), "autozoom" (zoom out the content to fit the WebView by width), "wide" (support the viewport meta tag, a wide viewport is used if the viewport meta tag is missing) and "nolongtouch" (WebView will not react to long touches).
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();
}
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" );
}
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/" );
}
See 'CreateWebView for more informations and a complete function list