User Tools

Site Tools


built_in:webview

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
built_in:webview [2014/12/05 13:43]
162.252.85.172 [Create]
built_in:webview [2016/07/12 15:18]
213.104.177.203
Line 1: Line 1:
 ====== WebView control ====== ====== WebView control ======
-===== Create ===== 
-You can create a control to display local or remote web pages in your App using the CreateWebView method of the app object: 
-<code>web = app.CreateWebView( width, height );</code> 
-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.+//(Information and examples taken from the DroidScript documentation)//
  
 +===== Description =====
 +You can create a control to display local or remote web pages in your App using the **CreateWebView** method of the **[[built_in:app|app]]** object:
 +<code>web = app.CreateWebView( width, height, options, zoom );</code>
 +options include **"IgnoreErrors", "NoScrollBars", "ScrollFade", "Overview", "AllowZoom"**
 +
 +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.
 <code> web.LoadUrl( url,options );</code> <code> web.LoadUrl( url,options );</code>
 <code> web.LoadHtml( html,baseFolder,options );</code> <code> web.LoadHtml( html,baseFolder,options );</code>
 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. 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. +If you need to, you can use the **Execute** method to execute JavaScript code within the WebView.
 <code> web.Execute( text );</code> <code> web.Execute( text );</code>
 +
 +
 ===== Methods ===== ===== Methods =====
 +Some controls use the same methods.\\
 +For examples of the **[[same methods]]** look here.
 ^Method ^Description ^ ^Method ^Description ^
-|WebView.Back() | | +|[[tips_tricks:webview_navigate|WebView.Back()]] | | 
-|WebView.CanGoBack() | |+|[[tips_tricks:webview_navigate|WebView.CanGoBack()]] | |
 |WebView.CanGoForward() | | |WebView.CanGoForward() | |
-|WebView.Destroy() | |+|WebView.Capture(filename) |captures jpeg of visible page | 
 +|WebView.ClearHistory() | |
 |WebView.Execute( code ) | | |WebView.Execute( code ) | |
 |WebView.Forward() | | |WebView.Forward() | |
Line 27: Line 35:
 |WebView.GetPosition() | | |WebView.GetPosition() | |
 |WebView.GetType() | | |WebView.GetType() | |
 +|WebView.GetUrl() | returns the current url|
 |WebView.GetVisibility() | | |WebView.GetVisibility() | |
 |WebView.GetWidth() | | |WebView.GetWidth() | |
 |WebView.LoadHtml( html,base,options ) | | |WebView.LoadHtml( html,base,options ) | |
 |WebView.LoadUrl( url,options ) | | |WebView.LoadUrl( url,options ) | |
-|WebView.Release() | | +|WebView.Print() |KitKat or later only 
-|WebView.SetBackColor( p1 ) | | +|WebView.SetBackColor( color ) | | 
-|WebView.SetBackGradient( p1,p2,p3,p4,p5,p6,p7 ) | | +|WebView.SetBackGradient( color1,color2,color3,p4,p5,p6,p7 ) | | 
-|WebView.SetBackGradientRadial( p1,p2,p3,p4,p5,p6,p7 ) | | +|WebView.SetBackGradientRadial( x,y,r,color1,color2,color3,p7 ) | | 
-|WebView.SetBackground( p1,p2 ) | |+|WebView.SetBackground( imagefile,options ) | |
 |WebView.SetMargins( left,top,right,bottom ) | | |WebView.SetMargins( left,top,right,bottom ) | |
 |WebView.SetOnProgress( callback ) | | |WebView.SetOnProgress( callback ) | |
-|WebView.SetPadding( p1,p2,p3,p4 ) | | +|WebView.SetPadding( width,height,top,bottom ) | | 
-|WebView.SetPosition( p1,p2,p3,p4 ) | |+|WebView.SetPosition( left,top,width,height ) | |
 |WebView.SetScale( x,y ) | | |WebView.SetScale( x,y ) | |
-|WebView.SetSize( p1,p2 ) | |+|WebView.SetSize( width,height ) | |
 |WebView.SetVisibility( HideShow ) | | |WebView.SetVisibility( HideShow ) | |
 +
 +===== Example - Remote =====
 +<code javascript>
 +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();
 +}
 +</code>
 +
 +===== Example - Local =====
 +<code javascript>
 +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" );
 +}
 +</code>
 +
 +===== Example - Direct =====
 +<code javascript>
 +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 style='color:#fff'>Hello World!<br>";
 +   html += "<img src='Img/Droid2.png'>";
 +   html += "</body></html>";
 +   web.LoadHtml( html, "file:///Sys/" );
 +}
 +</code>
built_in/webview.txt · Last modified: 2018/08/16 08:46 (external edit)