Web HTML Viewer

From Xojo Documentation

The HTML Viewer control renders HTML (like any web browser application). Typically, this is used to display pages that are not part of the web application.

You can pass this control the HTML text itself or tell it to load the HMTL specified by a URL. If the HTML is valid, it renders it. You can specify the default URL via the URL property in the Inspector for the control.

The commonly used properties and methods are listed below. Refer to WebHTMLViewer in the Language Reference for the complete list.


URL - Specify the URL in the Inspector to set the web page that is displayed when the Web Viewer first opens. Changing the URL in code immediately causes the URL contents to load.

HTML - Specify the HTML you wish to have rendered in the WebHTMLViewer.


LoadHTML - Use this method to load HTML (as a string) that you provide. If you have HTML in a file you want to display, first load the file into a String (using a TextInputStream) and then use this method to load the HTML string.

Print - Prints the contents of the HTML Viewer (some browsers will print the entire web page).

GotoURL - Used to display the web page at the supplied URL.


This code shows Wikipedia in a HTMLVIewer Viewer:


You can load HTML directly from a string:

HTMLViewer1.LoadHTML("<html><body><h1>Hello World!</h1></body></html>")

To display HTML that is in a file, first load the file into a String and then call LoadHTML:

Var htmlFile As New FolderItem("test.html")
If htmlFile <> Nil And htmlFile.Exists Then
Var html As String
Var htmlInput As TextInputStream
htmlInput = TextInputStream.Open(htmlFile)
html = htmlInput.ReadAll
Catch e As IOException
html = "<html><body><h1>Error loading file on server.</h1></body></html>"
End Try
End If

Example Projects

  • Examples/Web/Printing/HTMLViewerPrinting

See Also

WebHTMLViewer class