Class

MobileHTMLViewer


Description

A scrollable HTML viewer control.

Events

Name

Parameters

Returns

CancelLoad

url As String

Boolean

Closing

DocumentBegin

url As String

DocumentComplete

url As String

DocumentProgressChanged

url As String, percentageComplete As Integer

Error

errorNumber As Integer, errorMessage As String

JavaScriptRequest

method As String, parameters() As Variant

String

JavaScriptResult

result As String

NewWindow

url As String

MobileHTMLViewer

Opening

TitleChanged

newTitle As String

Property descriptions


MobileHTMLViewer.AccessibilityHint

AccessibilityHint As String

The accessibility hint is a longer description that is read aloud when VoiceOver is enabled.

Me.AccessibilityHint = "Click to calculate the value and display the next screen."

MobileHTMLViewer.AccessibilityLabel

AccessibilityLabel As String

The accessibility label of of a control is a short name that is read aloud when VoiceOver is enabled.

Me.AccessibilityLabel = "Calculate the value."

MobileHTMLViewer.CanGoBack

CanGoBack As Boolean

If True, it indicates that there is a prior page that can be navigated to using GoBack.

This property is read-only.

This code in the DocumentComplete event handler disables a Back button if there is no prior page:

BackButton.Enabled = Me.CanGoBack

MobileHTMLViewer.CanGoForward

CanGoForward As Boolean

If True, it indicates that there is a next page that can be navigated to using GoForward.

This property is read-only.

This code in the DocumentComplete event handler disables a Forward button if there is no next page:

ForwardButton.Enabled = Me.CanGoForward

MobileHTMLViewer.ControlCount

ControlCount As Integer

The number of child controls in the control.

This property is read-only.

Important

This is supported for iOS only.


MobileHTMLViewer.Enabled

Enabled As Boolean

Indicates whether the control is enabled or disabled.

Disable the button:

Button1.Enabled = False

MobileHTMLViewer.Height

Height As Integer

The height of the control.

This property is read-only on iOS.


MobileHTMLViewer.Left

Left As Integer

The left position of the control.

This property is read-only on iOS.


MobileHTMLViewer.LockBottom

LockBottom As Boolean

Determines whether the bottom edge of the control should stay at a set distance from the bottom edge of the parent control, if there is one, or the owning screen.

Important

This property is not currently supported for iOS. Use constraints instead.

This property can be set in the control's Inspector. The following example sets it in code.

Me.LockBottom = True

MobileHTMLViewer.LockLeft

LockLeft As Boolean

Determines whether the left edge of the control should stay at a set distance from the left edge of the parent control, if there is one, or the owning screen.

LockLeft and Locktop default to True when you add a new control to a screen. Existing controls will be altered only if LockRight and/or LockBottom are not set. LockLeft has no effect unless LockRight is True.

Important

This property is not currently supported for iOS. Use constraints instead.

This property can be set in the control's Inspector. The following example sets it in code.

Me.LockLeft = True

MobileHTMLViewer.LockRight

LockRight As Boolean

Determines whether the right edge of the control should stay at a set distance from the right edge of the parent control, if there is one, or the owning screen.

Important

This property is not currently supported for iOS. Use constraints instead.

This property can be set in the control's Inspector. The following example sets it in code.

Me.LockRight = True

MobileHTMLViewer.LockTop

LockTop As Boolean

Determines whether the top edge of the control should stay at a set distance from the top edge of the parent control, if there is one, or the owning screen.

LockTop and LockLeft default to True when you add a control to a screen. Existing controls will be altered only if LockRight and/or LockBottom are not set. LockTop has no effect unless LockBottom is True.

Important

This property is not currently supported for iOS. Use constraints instead.

This property can be set in the control's Inspector. The following example sets it in code.

Me.LockTop = True

MobileHTMLViewer.Name

Name As String

The name of the control.

This property is read-only.


MobileHTMLViewer.Parent

Parent As MobileUIControl

The parent (sometimes called a "Super") class of the control.

This property is read-only.


MobileHTMLViewer.TintColor

TintColor As ColorGroup

Changes a control's tint color.

Important

This is supported for iOS only.

On iOS, the following controls support TintColor:

Enum

Description

ProgressBar

The area indicating the value of the control will be drawn in the TintColor.

Slider

The area indicating the value of the control will be drawn in the TintColor.

TextArea

The cursor and text highlight color will be drawn in the TintColor.

TextField

The cursor and text highlight color will be drawn in the TintColor.


MobileHTMLViewer.Top

Top As Integer

The top position of the control.

This property is read-only on iOS.


MobileHTMLViewer.Visible

Visible As Boolean

Indicates whether the control is visible.

Make a button invisible:

Button1.Visible = False

MobileHTMLViewer.Width

Width As Integer

The width of the control.

This property is read-only on iOS.

Method descriptions


MobileHTMLViewer.AddConstraint

AddConstraint(constraint As iOSLayoutConstraint)

Adds a constraint to the control.

This constraint is used by child controls that have been added to this control.

Important

This is supported for iOS only.


MobileHTMLViewer.AddControl

AddControl(child As MobileUIControl)

Adds a child control to the control.

Important

This is supported for iOS only.


MobileHTMLViewer.Cancel

Cancel

Cancels any current operations.

Me.Cancel

MobileHTMLViewer.ClearFocus

ClearFocus

Removes the focus from the control.

TextField1.ClearFocus

MobileHTMLViewer.ControlAt

ControlAt(index As Integer) As MobileUIControl

Gets the child control at the specified index.

Important

This is supported for iOS only.


MobileHTMLViewer.Controls

Controls As Iterable

Allows you to iterate through all the controls that have been added to this control.

Important

This is supported for iOS only.


MobileHTMLViewer.ExecuteJavaScript

ExecuteJavaScript(js As String)

Asynchronously executes the passed JavaScript in the context of the currently loaded page.

On Android, this causes the JavaScriptResult event to fire passing it values returned by the JavaScript.

Attempting to execute JavaScript before the page finishes loading (or if no page is loaded) is undefined and is unlikely to work.

This code will populate the search field on the wikipedia page (assuming it was previously loaded):

Var jsSrc As String
jsSrc = "document.forms[0].elements['search'].value=""xojo"";"
HTMLViewer1.ExecuteJavaScript(jsSrc)

This code writes text to the HTML document:

Var this As String
this = "document.writeln(""hello"");"
HTMLViewer1.ExecuteJavaScript(this)

MobileHTMLViewer.ExecuteJavaScriptSync

ExecuteJavaScriptSync(js As String) As Variant

Synchronously executes the passed JavaScript in the context of the currently loaded page and returns the result. Only strings and numbers may be returned.

Attempting to execute JavaScript before the page finishes loading (or if no page is loaded) is undefined and is unlikely to work.

Important

This is supported for iOS only.


MobileHTMLViewer.GoBack

GoBack

Navigates to the prior page.

On a back button Pressed event handler, you can write:

HTMLViewer1.GoBack

MobileHTMLViewer.GoForward

GoForward

Navigates to the next page.

On a forward button Pressed event handler, you can write:

HTMLViewer1.GoForward

MobileHTMLViewer.Handle

Handle As Ptr

The handle to the underlying native OS control.


MobileHTMLViewer.LoadPage

LoadPage(file As FolderItem)

Displays the HTML passed.


MobileHTMLViewer.LoadPage

LoadPage(html As String)

Displays the HTML passed.

iOS sandboxing of the app and the HTML Viewer can prevent the HTML Viewer from seeing files that are in the app's Documents folder. This code can be used to provide access to files in the Documents folder:

Declare Function NSClassFromString Lib "Foundation.framework" (clsName As CFStringRef) As ptr
Declare Function URLWithString Lib "Foundation.framework" Selector "URLWithString:" ( id As Ptr, URLString As CFStringRef ) As Ptr

Declare Sub loadFileURL Lib "UIKit.framework" Selector "loadFileURL:allowingReadAccessToURL:" (obj As Ptr, url As Ptr, readAccessURL As Ptr)

' htmlFile is a FolderItem from SpecialFolder.Documents
Var nsURL As Ptr = URLWithString(NSClassFromString("NSURL"), htmlFile.URLPath)
Var readURL As Ptr = URLWithString(NSClassFromString("NSURL"), htmlFile.parent.URLPath)

loadFileURL(HTMLViewer1.Handle, nsURL, readURL) ' Display the contents in an MobileHTMLViewer

MobileHTMLViewer.LoadURL

LoadURL(url As String)

Displays the specified URL.

Be sure to include the appropriate prefix, such as "https://".

To load HTML from a file on the device or to load HTML as a String directly, use LoadPage.

Display wikipedia:

HTMLViewer1.LoadURL("https://www.wikipedia.org")

MobileHTMLViewer.Refresh

Refresh

Marks the control so that it will be redrawn during the next event loop.

Call Refresh to force a Canvas to redraw itself:

Canvas1.Refresh

MobileHTMLViewer.RemoveConstraint

RemoveConstraint(constraint As iOSLayoutConstraint)

Removes a constraint from the control.

Important

This is supported for iOS only.


MobileHTMLViewer.RemoveControl

RemoveControl(child As MobileUIControl)

Removes the control from the control.

Important

This is supported for iOS only.


MobileHTMLViewer.SetFocus

SetFocus

Sets the focus to the control.

TextField1.SetFocus

Event descriptions


MobileHTMLViewer.CancelLoad

CancelLoad(url As String) As Boolean

Returns a Boolean. Return True to cancel loading the page.


MobileHTMLViewer.Closing

Closing

Called when the control's layout is closing.


MobileHTMLViewer.DocumentBegin

DocumentBegin(url As String)

Fires when the HTML page is starting to load.


MobileHTMLViewer.DocumentComplete

DocumentComplete(url As String)

Called when the HTML page is finished loading.


MobileHTMLViewer.DocumentProgressChanged

DocumentProgressChanged(url As String, percentageComplete As Integer)

Fires when the progress has been updated. If percentageComplete is -1, the percentage cannot be determined.


MobileHTMLViewer.Error

Error(errorNumber As Integer, errorMessage As String)

Fires when an error occurs.

The errors you receive are the standard HTTP Status Codes.


MobileHTMLViewer.JavaScriptRequest

JavaScriptRequest(method As String, parameters() As Variant) As String

Called when a JavaScript executed via ExecuteJavaScript or ExecuteJavaScriptSync calls executeInXojo() or executeInXojoSync() on iOS or xojo.execute() on Android.

Note

iOS: A JavaScript executed via ExecuteJavaScript or ExecuteJavaScriptSync can call executeInXojo() or executeInXojoSync() on iOS to pass data back to the HTMLViewer via this event. Both can be passed any number of parameters though the first parameter must be a string. For all subsequent parameters, only strings and numbers are supported. The executeInXojo() method is asynchronous and thus will not receive a value returned by this event. The executeInXojoSync() method is synchronous and thus should be called as a function as it will receive the value returned by this event.

Note

Android: A JavaScript executed via ExecuteJavaScript can call xojo.execute() on Android to pass data back to the HTMLViewer via this event. A method name and up to 5 parameters can be passed back to Xojo.


MobileHTMLViewer.JavaScriptResult

JavaScriptResult(result As String)

Called on Android only when ExecuteJavaScript has been called and has been passed a JavaScript that calls xojo.execute().

The JavaScript can pass back to this event a method name and up to five parameters.

Important

This event is supported for Android only.


MobileHTMLViewer.NewWindow

NewWindow(url As String) As MobileHTMLViewer

Called when the HTML on page requests that a URL be opened in a new HTML viewer.

Return an instance of an HTMLViewer to load the page in that viewer or Return Nil if you do not want to allow URL to open at all.


MobileHTMLViewer.Opening

Opening

Called when the control's layout is opening.

This is where you typically put initialization code.

This example in the Opening event of a label sets its text to "Hello":

Me.Text = "Hello"

MobileHTMLViewer.TitleChanged

TitleChanged(newTitle As String)

Fires when the Title of the Web page has been determined or has changed.

The renderer, which varies by OS, determines the maximum number of characters that are returned in NewTitle. You should test this in your projects to determine a maximum number of characters, keeping in mind that this could change at any time due to the underlying renderer and operating system.

Notes

iOS requires the use of secure "https" connections or the page will not display.

Compatibility

Mobile projects on all supported mobile operating systems.

See also

MobileUIControl parent class; URLConnection class