Class
HTMLViewer (deprecated)
Warning
This item was deprecated in version 2021r3. Please use DesktopHTMLViewer as a replacement.
Description
Renders HTML and provides basic navigation features.
Properties
Name |
Type |
Read-Only |
Shared |
---|---|---|---|
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
Methods
Name |
Parameters |
Returns |
Shared |
---|---|---|---|
FileType As String |
|||
Type As String |
|||
js As String |
|||
js As String |
|||
[EraseBackground As Boolean] |
|||
Source As String, RelativeTo As FolderItem |
|||
File As FolderItem |
|||
URL As String |
|||
eraseBackground As Boolean |
|||
Events
Name |
Parameters |
Returns |
---|---|---|
URL As String |
||
URL As String |
||
URL As String |
||
String |
||
Key As String |
||
Key As String |
||
url As String</api/data_types/string> |
HTMLViewer |
|
IsSecure As Boolean |
||
NewStatus As String |
||
NewTitle As String |
Property descriptions
HTMLViewer.Active
Active As Boolean
Indicates whether the RectControl is active.
This property is read-only.
Active is False when the RectControl's window is not in the foreground. When a Window is deactivated, its controls are automatically deactivated unless AutoDeactivate is set to False.
HTMLViewer.AllowAutoDeactivate
AllowAutoDeactivate As Boolean
Determines whether the control should be deactivated (on macOS) when the parent window is deactivated. The default is True.
HTMLViewer.AllowTabStop
AllowTabStop As Boolean
If True, the RectControl is in the Tab Order and accepts the focus when the user tabs into it. The default is True. If False, the user cannot tab into it to give it the focus. However, the RectControl can gain the focus by other means, such as the user's clicking on it or by setting the focus in code.
This example removes the control from the Tab Order:
Me.AllowTabStop = False
HTMLViewer.CanGoBack
CanGoBack As Boolean
If True, it indicates that there is a prior page that can be navigated to using HTMLViewer.
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
HTMLViewer.CanGoForward
CanGoForward As Boolean
If True, it indicates that there is a next page that can be navigated to using HTMLViewer.
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
HTMLViewer.Enabled
Enabled As Boolean
Determines if the control should be enabled when the owning window is opened.
A disabled control cannot be clicked and cannot receive the focus.
This example disables the control. Its caption is grayed out.
Me.Enabled = False
HTMLViewer.Handle
Handle As Integer
Returns a handle to the control.
This property is read-only.
For interfacing with Mac APIs using Declare).
On Windows returns the HWND of the control.
On Linux it returns a GtkWidget.
The following gets a handle to the control.
Var i As Integer = Me.Handle
HTMLViewer.Height
Height As Integer
The height (in points) of the control.
This example sets the height of the control to 100:
Me.Height = 100
HTMLViewer.Index
Index As Integer
If the control is used in a control set, this specifies the control's index in the set.
This property is read-only.
The control set is often used to manage a group of RadioButtons since a single RadioButton in a window doesn't make much sense. Most typically, you create an instance of the RadioButton, assign 0 to its Index property, and then duplicate it. This increments the value of Index for each new instance but retain the original control's name.
To determine which RadioButton the user clicked, use the Action event handler of the control set. The parameter Index contains the value of Index for the RadioButton that was clicked. The event handler is this:
Sub Action(Index As Integer)
Label1.Text = "You chose radio button " + index.ToString + "."
End Sub
To set a RadioButton in a control set, you use its Index property to refer to the RadioButton whose value you want to set. For example, the following line selects the second RadioButton from code:
RadioButton1(1).Value = True ' 0-based
HTMLViewer.IsAvailable
IsAvailable As Boolean
If True, it indicates that the required support libraries required by the control were loaded.
This property is read-only.
On Windows, HTMLViewer uses Internet Explorer or WebKit (depending on the Renderer property), on macOS and Linux, it uses WebKit.
This example in the Open event handler calls the IsAvailable property prior to proceeding:
If Me.IsAvailable Then
Me.LoadURL("http://www.wikipedia.org")
End If
HTMLViewer.Left
Left As Integer
The left side of the control in local coordinates (relative to the window).
The following example moves the control 100 points from the left side of the window:
Me.Left = 150
HTMLViewer.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 window.
This property can be set in the control's Inspector. The following example sets it in code.
Me.LockBottom = True
HTMLViewer.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 window.
Beginning with version 2009r5, LockLeft and Locktop default to True when you add a new control to a window. Existing controls will be altered only if LockRight and/or LockBottom are not set. LockLeft has no effect unless LockRight is True.
This property can be set in the control's Inspector. The following example sets it in code.
Me.LockLeft = True
HTMLViewer.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 window.
This property can be set in the control's Inspector. The following example sets it in code.
Me.LockRight = True
HTMLViewer.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 window.
Beginning with version 2009r5, LockTop and LockLeft default to True when you add a control to a window. Existing controls will be altered only if LockRight and/or LockBottom are not set. LockTop has no effect unless LockBottom is True.
This property can be set in the control's Inspector. The following example sets it in code.
Me.LockTop = True
HTMLViewer.MouseCursor
MouseCursor As MouseCursor
The cursor to be displayed while the mouse is within the control and both the DesktopApplication and Window class's MouseCursor properties are Nil.
If the DesktopApplication class's MouseCursor property is not Nil or the Window's MouseCursor property is not Nil, then any control's MouseCursor property is ignored. You can use a cursor stored in the Cursors module. On Macintosh, you can also obtain a MouseCursor from a resource file.
This line in the Open event of the control sets the default cursor to the finger pointer.
Me.MouseCursor = System.Cursors.FingerPointer
HTMLViewer.MouseX
MouseX As Integer
The X coordinate of the mouse (points). Measured from the top-left corner of the control.
This property is read-only.
This code is in the MouseDown event of a TextField and displays the X-coordinate at the point of the MouseDown event.
Me.Value = Str(Me.MouseX)
HTMLViewer.MouseY
MouseY As Integer
The Y coordinate of the mouse (points). Measured from the top-left corner of the control.
This property is read-only.
This code is in the MouseDown event of a TextField and displays the Y-coordinate at the point of the MouseDown event.
Me.Value = Str(Me.MouseY)
HTMLViewer.Name
Name As String
The name of the control. Set the name of the control in the Inspector.
This property is read-only.
HTMLViewer.PanelIndex
PanelIndex As Integer
If the control has been placed on a TabPanel or PagePanel control, this is the panel (page/tab) that the control is on. If the control is not on a panel, it returns -1.
The first panel is numbered zero. If the control has been placed on a panel of a TabPanel or PagePanel control, it returns the panel number. If the control is not on a PagePanel or TabPanel, it returns -1. If you change the PanelIndex to a nonexistent panel, the control will disappear until you give it a PanelIndex value that corresponds to a panel that exists.
If you are looking to change the currently selected panel (page/tab), use PagePanel.
This code displays the panel index of the control that is on the page.
Label3.Value = Str(Me.PanelIndex)
HTMLViewer.Parent
Parent As Control
Used to get and set the control's parent control or window.
Returns Nil if the parent is the window. Assign Nil to make the control's parent the window, even if it is enclosed by another control. The child control's behavior in the IDE will reflect the parent's state. If the parent control is somehow in another window, an InvalidParentException will occur.
The following example sets the parent of the control to the window.
Me.Parent = Nil
HTMLViewer.Renderer
Renderer As Integer
Used to specify the rendering engine used on Windows. Choices are Native (0) or WebKit (1). You can only set this property in the Inspector for the control.
This property is read-only.
The Native renderer is Internet Explorer.
Using WebKit on Windows adds the entire Chromium Embedded Framework 3 (CEF3) engine to your app, increasing its size by about 100MB.
If you need plugins when using WebKit, add them to the WebKitPlugins folder in the Libs folder for your application.
Setting this property at runtime has no effect.
When using Native, Windows uses an older version of the Internet Explorer rendering engine. You can switch to a more recent version specifically for your app with code like this:
Var reg As New RegistryItem("HKEY_CURRENT_USER\SOFTWARE\Microsoft")
reg = reg.AddFolder("Internet Explorer")
reg = reg.AddFolder("Main")
reg = reg.AddFolder("FeatureControl")
reg = reg.AddFolder("FEATURE_BROWSER_EMULATION")
reg.Value(App.ExecutableFile.Name) = &h2710 ' Use IE 11 renderer
HTMLViewer.Scope
Scope As Integer
Used to determine whether access to the control is Public (0) or Private (2). The default is Public.
This property is read-only.
If the Scope of a control is set to Private, it cannot be accessed from outside its parent window.
HTMLViewer.TabIndex
TabIndex As Integer
The RectControl's position in the Tab Order. It is 0-based. A TabIndex of 0 is the first RectControl to get the focus.
On the Mac you need Full Keyboard Access turned on in System Preferences (Keyboard->Shortcuts) in order to manually set focus to non-text controls.
This example sets the control's TabIndex.
Me.TabIndex = 2
HTMLViewer.Tooltip
Tooltip As String
Text of help message displayed as a Windows or Linux "tooltip" or macOS help tag.
The tip/tag is displayed when the user hovers the mouse cursor over the control.
This example adds a tooltip to a BevelButton that has an icon.
Me.CaptionAlignment = 0 ' left
Me.CaptionDelta = 10
Me.Tooltip = "Click to bark."
Me.Icon = Woof ' added to the project
Me.CaptionPosition = 2
HTMLViewer.Top
Top As Integer
The top of the control in local coordinates (relative to the window).
This example sets the top of the control to 140 points from the top of the window:
Me.Top = 140
HTMLViewer.Transparent
Transparent As Boolean
Determines whether the control is transparent on Windows. The default is False. Has no effect on macOS or Linux.
Transparent controls draw more slowly and use more memory in order to cache the background. Unless you absolutely require transparency, leave this set to False.
For projects that were created prior to 2018r1, this property defaults to True to emulate previous behavior. Consider changing it to False to improve performance if you do not require transparency.
HTMLViewer.TrueWindow
TrueWindow As Window
Returns a reference to the actual enclosing Window.
This property is read-only.
TrueWindow walks up the window hierarchy and finds the actual enclosing window regardless of how deeply nested the RectControl or DesktopContainer hierarchy is.
Window also has a TrueWindow property.
This example accesses the TrueWindow and displays its Title property in a TextField.
TextField1.Text = Me.TrueWindow.Title
HTMLViewer.UserAgent
UserAgent As String
Supports getting and setting a custom user agent string.
UserAgent works on macOS and Windows (using the Native Renderer). Changing it has no effect on Linux or when on Windows using the WebKit Renderer.
This example sets the UserAgent.
If Me.IsAvailable Then
Var agent As String
agent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16"
Me.UserAgent = agent
End If
HTMLViewer.UseSandbox
UseSandbox As String
If True, the JavaScript (if any) embedded in the page being viewed in the HTMLViewer will be unable to access the HTMLViewer's parent webpage.
HTMLViewer.Visible
Visible As Boolean
Determines whether the control is visible when its owning window is opened. The default is True: the control is visible.
The following code in the DisclosureTriangle Action event handler displays or hides a ListBox on the window:
ListBox1.Value = Me.Visible
HTMLViewer.Width
Width As Integer
The width (in points) of the control.
The following example resizes the control:
Me.Width = 200
HTMLViewer.Window
Window As Window
The control's parent window.
This property is read-only.
This code gets the parent window's Title property.
TextField1.Text = Me.Window.Title
Method descriptions
HTMLViewer.AcceptFileDrop
AcceptFileDrop(FileType As String)
Permits documents of type FileType to be dropped on the control. FileType must be a file type that you defined in via the FileType class or the File Type Sets Editor.
This code in the Open event of an ImageWell makes it possible for the user to drop either a picture or a file that is a jpeg image. The File Type Sets editor was used to define the “image/jpeg” file type. It is one of the “Common File Types” that is available in the editor.
Me.AcceptPictureDrop
Me.AcceptFileDrop("image/jpeg")
To restrict file drops to just folders (and not files), you can put this code in the DragEnter event:
If Not obj.FolderItem.IsFolder Then Return True
HTMLViewer.AcceptPictureDrop
AcceptPictureDrop
Permits pictures to be dropped on the control.
If a control should accept pictures in a drag and drop, then AcceptPictureDrop needs to be called prior to the drop. Typically, it is in the Open event of the control itself. For example, the line:
Me.AcceptPictureDrop
in the Open event of the control that will receive the dragged pictures is needed. When the picture is dropped, the DropObject event is called and this is where you will put your code to handle the drop.
Canvas.Open:
Me.AcceptPictureDrop
Canvas.DropObject:
If obj.PictureAvailable Then
Me.Backdrop = obj.Picture
End If
HTMLViewer.AcceptRawDataDrop
AcceptRawDataDrop(Type As String)
Permits data (of the Type specified) to be dropped on the control.
The following specfies a generic file type defined in the File Type Sets editor.
Me.AcceptRawDataDrop("????")
HTMLViewer.AcceptTextDrop
AcceptTextDrop
Permits text to be dropped on the control.
This line in the Open event of a control that can accept dragged text.
Me.AcceptTextDrop
HTMLViewer.Cancel
Cancel
Cancels any current operations.
Me.Cancel
HTMLViewer.Close
Close
Closes a control.
Closing a control permanently removes the control from memory, making it impossible to access. You can close both non-indexed controls and indexed controls. When you close an indexed control, the indexes for the remaining controls will shift downward so that the indexes start with zero and are consecutive.
The following code closes the control. When this is executed from a visible control, the control disappears from the window.
Me.Close
HTMLViewer.DrawInto
DrawInto(g As Graphics, x As Integer, y As Integer)
Draws the contents of the RectControl into the specified Graphics context. The parameters x and y are the coordinates of the top, left corner.
This method does not work with HTMLViewer and OpenGLSurface.
This example draws the current control into the Graphics of a Picture and then displays it as the Backdrop of a Canvas:
Var p As New Picture(Me.Width, Me.Height)
Me.DrawInto(p.Graphics, 0, 0)
Canvas1.Backdrop = p
HTMLViewer.ExecuteJavaScript
ExecuteJavaScript(js As String)
Asynchronously executes the passed JavaScript in the context of the currently loaded page.
Attempting to execute JavaScript before the page finishes loading (or if no page is loaded) is undefined and is unlikely to work.
In order to call JavaScript on Windows using the Native renderer, a document must already be loaded into the HTMLViewer. If no document is loaded, an HTMLViewerException is raised.
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)
HTMLViewer.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.
In order to call JavaScript on Windows using the Native renderer, a document must already be loaded into the HTMLViewer. If no document is loaded, an HTMLViewerException is raised.
HTMLViewer.GoBack
GoBack
Navigates to the prior page.
On a back button Action event handler, you can write:
HTMLViewer1.GoBack
HTMLViewer.GoForward
GoForward
Navigates to the next page.
On a forward button Action event handler, you can write:
HTMLViewer1.GoForward
HTMLViewer.Invalidate
Invalidate([EraseBackground As Boolean])
Similar to RefreshRect, but causes the specified region of the RectControl to be marked dirty and to be redrawn when the window contents need to be redrawn. The region to be redrawn is specified by the X, Y, Width, and Height parameters. This form of Invalidate was formerly called InvalidateRect.
The following code refreshes the control. EraseBackground defaults to True.
Me.Invalidate(False)
HTMLViewer.LoadPage
LoadPage(Source As String, RelativeTo As FolderItem)
Loads the the supplied File into the HTMLViewer. File must be an actual file and not a folder.
HTMLViewer.LoadPage
LoadPage(File As FolderItem)
Loads the the supplied File into the HTMLViewer. File must be an actual file and not a folder.
Any links will be resolved relative to the passed RelativeTo FolderItem.
On Windows, temporary files are created beside the passed RelativeTo FolderItem. If the temporary files cannot be created, then an exception error may be thrown. This can happen, for example, if you are trying to write to a read-only volume or you don't have write permissions.
In this example, the raw HTML is in a TextArea:
Var f As FolderItem = FolderItem.TemporaryFile
HTMLViewer1.LoadPage(TextArea1.Text, f)
This example loads an HTML file from disk. The file type has been added using the File Types Set Editor:
Var f As FolderItem
f = FolderItem.ShowOpenFileDialog("text/html")
If f <> Nil Then
HTMLViewer1.LoadPage(f)
End If
HTMLViewer.LoadURL
LoadURL(URL As String)
Loads the passed HTTP URL. Any protocol other than HTTP may or may not work as that is dependent on operating system behavior.
On macOS, you need to ensure the URL is prefixed with "http://" or "https://" in order for it to load.
This example loads a URL entered by the user in a TextField:
Var url As String = URLField.Value
If Left(url, 7) <> "http://" Then url = "http://" + url
HtmlViewer1.LoadURL(url)
HTMLViewer.Print
Print(showPrintDialog As Boolean = True)
Prints the contents of the HTMLViewer. On Linux, this requires Webkit 1.1.5 or newer.
This example prints the current page.
HTMLViewer1.Print
HTMLViewer.Refresh
Refresh(eraseBackground As Boolean)
Repaints the portion specified of the contents of the control immediately.
Calling this frequently can cause the code executing to slow down. It is often preferable to call RectControl instead.
Refresh the entire area:
Me.Refresh(False)
Refresh a portion of the area:
Me.Refresh(100, 150, 200, 300)
HTMLViewer.SetFocus
SetFocus
If applicable, sets the focus to the RectControl. KeyDown events are directed to the control.
If the control cannot get the focus on the platform on which the application is running, SetFocus does nothing. The SetFocus method of the Window class or the ClearFocus method can be used to remove the focus from the control that currently has the focus, leaving no control with the focus.
On the Mac you need Full Keyboard Access turned on in System Preferences (Keyboard->Shortcuts) in order to manually set focus to non-text controls.
The following example sets the focus to TextField1. If another control has the focus when this line is executed, then the user sees that TextField1 gets the focus.
TextField1.SetFocus
HTMLViewer.ZoomTextIn
ZoomTextIn
Augments the size of the text used to display the HTML page content. You can use ZoomTextIn several times.
The reverse action is achieved with the ZoomTextOut method.
This example is the Pressed event of a SegmentedButton:
If segmentIndex = 0 Then
HtmlViewer1.ZoomTextIn
ElseIf segmentIndex = 1 Then
HtmlViewer1.ZoomTextOut
End If
HTMLViewer.ZoomTextOut
ZoomTextOut
Reduces the size of the text used to display the HTML page content. You can use ZoomTextOut several times.
The reverse action is achieved with the ZoomTextIn method.
This example is the Action event of a SegmentedButton:
If itemIndex = 0 Then
HtmlViewer1.ZoomTextIn
ElseIf itemIndex = 1 Then
HtmlViewer1.ZoomTextOut
End If
Event descriptions
HTMLViewer.CancelLoad
CancelLoad(URL As String) As Boolean
Returns a Boolean. Return True to cancel loading the page.
HTMLViewer.Close
Close
The control is about to close.
HTMLViewer.DocumentBegin
DocumentBegin(URL As String)
Fires when the HTML page is starting to load.
HTMLViewer.DocumentComplete
DocumentComplete(URL As String)
Called when the HTML page is finished loading.
HTMLViewer.DocumentProgressChanged
DocumentProgressChanged(URL As String, PercentageComplete As Integer)
Fires when the progress has been updated. If percentageComplete is -1, the percentage cannot be determined.
HTMLViewer.Error
Error(ErrorNumber As Integer, ErrorMessage As String)
Fires when an error occurs.
The errors you receive are the standard HTTP status codes: * HTTP Status Codes
HTMLViewer.JavaScriptRequest
JavaScriptRequest(method As String, parameters() As Variant) As String
Called when a JavaScript executed via ExecuteJavaScript or ExecuteJavaScriptSync calls ExecuteInXojo or ExecuteInXojoSync.
A JavaScript executed via ExecuteJavaScript or ExecuteJavaScriptSync can call executeInXojo() or executeInXojoSync() 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.
HTMLViewer.KeyDown
KeyDown(Key As String) As Boolean
The user has pressed the Key passed while the control has the focus.
How KeyDown works depends on the type of control.
TextField and TextArea Returning True means the key is intercepted, preventing the key from actually reaching the control at all. This would be useful if you want to override the behavior of the tab key for example. Returning False means the key reaches the control.
All Other Controls Returning True prevents the KeyDown event on the parent control (usually the window) from executing. Returning False results in the execution of the KeyDown event of the parent control.
HTMLViewer.KeyUp
KeyUp(Key As String)
Fires when the passed Key is released in the RectControl that has the focus.
It is not guaranteed to be the same key that received the KeyDown event.
HTMLViewer.NewWindow
NewWindow(url As String</api/data_types/string>) As HTMLViewer
Called when a new browser window is requested.
Returns a new instance of an HTMLViewer to load the page in that viewer or Return Nil when you do not want to allow the window to open.
HTMLViewer.Open
Open
The control is about to be displayed. Use this event to initialize a control.
The Open event is called after the Constructor.
Be warned that initializing control property values using the Constructor instead of the Open event may result in those property values being overwritten by what is set in the Inspector. For best results, use the Open event for control initialization rather than the control Constructor.
If the control is supposed to handle drag and drop, you need to tell it which type of item it needs to be able to handle. The following example informs the control that pictures and files can be dropped on it. The type of the file it needs to support is specified via the File Types Editor.
Sub Open()
Me.AcceptPictureDrop
Me.AcceptFileDrop("JPEG")
End Sub
HTMLViewer.SecurityChanged
SecurityChanged(IsSecure As Boolean)
Fires when the document's security has changed. For example, entering a secure web site will cause this event to fire.
This event is only called on Microsoft Windows when using the Native renderer.
HTMLViewer.StatusChanged
StatusChanged(NewStatus As String)
Fires when the Status text has changed for the window.
Due to changes made to the CEF3 library (Chromium Embedded Framework) this event is not called on Windows when Renderer = WebKit.
HTMLViewer.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
On macOS, the HTMLViewer supports getting and setting a custom user agent string and increasing or decreasing the font size.
Exchanging data with javascript
A JavaScript executed via ExecuteJavaScript or ExecuteJavaScriptSync can call executeInXojo() or executeInXojoSync() to pass data back to the HTMLViewer via the JavaScriptRequest 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 the JavaScriptRequest event. The executeInXojoSync() method is synchronous and thus should be called as a function as it will receive the value returned by the JavaScriptRequest event.
On Windows you need to use the WebKit rendering engine for executeInXojo() or executeInXojoSync() to work.
App transport security
Starting with MacOS 10.11 and Xojo 2018r4, your apps have to use secure "https" connections or you will get this error: "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection". You can work around this by providing a plist with your app to indicate what non-secure URLs you are using. For more information: * Using Non-Secure URLs on macOS and iOS
Webkit on windows
You can use WebKit on Windows by setting the Renderer property to WebKit (1). Using WebKit on Windows adds the entire Chromium Embedded Framework 3 (CEF3) engine to your app, increasing its size by about 100MB.
To make plugins available to WebKit on Windows, create a folder called WebKitPlugins within your Libs folder in your application folder and place the plugins you need there.
When using WebKit on Windows, HTMLViewer.Handle returns a pointer to the cef_browser_t struct.
Windows ie version
On Windows, the Native Renderer is probably using an older version of the Internet Explorer renderer. This may result in web pages that do not display or work as you expect. You can tell Windows to use a newer version of the IE rendering engine with a Registry setting. This is how you can change it using Xojo:
#If TargetWindows
' This code handles both 64 and 32-bit builds
Var reg As New RegistryItem("HKEY_CURRENT_USER\SOFTWARE\Microsoft")
reg = reg.AddFolder("Internet Explorer")
reg = reg.AddFolder("Main")
reg = reg.AddFolder("FeatureControl")
reg = reg.AddFolder("FEATURE_BROWSER_EMULATION")
' Source MS documentation: https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/general-info/ee330730(v=vs.85)
reg.Value(App.ExecutableFile.Name) = CType(11000 , Int32)
#Endif
Another issue to keep in mind is if Internet Explorer 11 has the option "Display intranet sites in Compatibility View" selected in the "Compatibility View Settings" pane, then IE will most likely still render using IE7. If you control the source to the content you want to display, you can include this in the <head> section of the HTML document: <pre class="code"><meta http-equiv="X-UA-Compatible" content="IE=11"></pre>
And also use HTML5 DOCTYPE at the start of the document: <pre class="code"><!DOCTYPE html></pre>
Windows performance
On Windows, the Native Renderer might not use the GPU by default, which may result in slower rendering speeds depending on what you are displaying. You can enable it via the Registry:
Var reg As New RegistryItem("HKEY_CURRENT_USER\SOFTWARE\Microsoft")
reg = reg.AddFolder("Internet Explorer")
reg = reg.AddFolder("Main")
reg = reg.AddFolder("FeatureControl")
reg = reg.AddFolder("FEATURE_GPU_RENDERING")
reg.Value(App.ExecutableFile.Name) = 1
Linux support
If it is available, the Linux HTMLViewer uses WebKit (libwebkitgtk version 3).
Refer to the System Requirements for current release section for commands that you can use to install libwebkitgtk v3 on various Linux distributions.
On Linux, HTMLViewer.Handle returns the GtkScrolledWindow that hosts the WebKitWebView control (please refer to the WebKitGTK site for information on how to use this system control).
Sample code
To implement a simple web browser, create a window with a large HTML Viewer control. Set its LockLeft, LockTop, LockRight, and LockBottom properties so that it resizes as the user resizes the window. Use a TextField as the URL entry area and a PushButton as the browser's Go button. That is, the user clicks Go to display the URL entered into the TextField.
In this example, the HTMLViewer is named “HTML”. The following code is in the Action event of the PushButton:
HTML.LoadURL(TextField.Value)
You can use a ProgressBar to indicate that the web page is loading. In the HTMLViewer's DocumentBegin event, initialize and show the ProgressBar with the code:
ProgressBar1.Value = 0
ProgressBar1.Visible = True
In the DocumentProgressChanged event, increment the value of the ProgressBar. This event handler is passed the value of PercentageComplete (0 to 100).
If percentageComplete = -1 Then ' if it cannot be determined
ProgressBar1.Maximum = 0 ' display indeterminate progress
Else
ProgressBar1.Maximum = 100
End if
ProgressBar1.Value = percentageComplete
In the DocumentComplete event handler, hide the ProgressBar with the line:
ProgressBar1.Visible = False
When the title of the web page has been received, you can display it in the window's Title bar using the HTMLViewer's TitleChanged event. It is passed the new title in the String parameter newTitle. Update the window title with the line:
Title = newTitle
Use a second TextField to display the status of the load process. In the HTMLViewer's StatusChanged event handler, set the value of this TextField. This event handler is passed the current status in the String parameter, NewStatus. Display this string with the following line in the StatusChanged event:
TextField1.Text3 = NewStatus
If a new browser window is supposed to open, you need to insert some code to handle this event. For example, the user clicks a link that is supposed to display the new page in another window. Use the NewWindow event handler to create the window. The following code assumes that the browser is contained in a window called MainWindow.
Var w As New MainWindow
Title = "New Window" //Title property of new window
w.Show
Return w.HTML
Compatibility
All project types on all supported operating systems.
See also
RectControl parent class; URLConnection and URLConnection classes