UserGuide

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.

Properties

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.

Methods

LoadPage

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).

ShowURL

Used to display the web page at the supplied URL.

Usage

Web HTML Viewer showing an invoice to print

This code shows Wikipedia in a HTMLVIewer Viewer:

HTMLViewer1.ShowURL("http://www.wikipedia.org%22)

You can load HTML directly from a string:

HTMLViewer1.LoadPage("<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 LoadPage:

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

Example Projects

  • Examples/Web/Printing/HTMLViewerPrinting
  • Examples/Web/Controls/AudioPlayer

See Also

WebHTMLViewer class; UserGuide:Web UI topic