From Xojo Documentation


WebHTMLViewer.LoadPage(HTML as String)

Supported for all project types and targets.

Loads the specified HTML into the WebHTMLViewer.


Web pages loaded using LoadPage cannot have separate origins. This primarily means that the SRC tag cannot load data (such as external JavaScript source) from outside locations. Instead, embed all the necessary content into the string before calling LoadPage.

LoadPage creates a WebFile behind the scenes. Use the URL property to load your own data without relying on system-created WebFile.

Sample Code

You can load HTML directly from a string like so:

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

To display HTML from a file, first load the file into a String:

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

This code executes JavaScript within the HTML:

Var js As String = "<script type=""text/javascript"">document.write(""Hello World!"")</script>"
Var html As String = "<html><body>" + js + "</body></html>"

To display an image you have to include the proper URL path to it. If you add an image to the project and call it CompanyLogo, then you can use code like this to display it:

// Replace the logo in the HTML with a valid URL for where the web app is located
Var html As String = "<html><body><img src='Box128.png' width='128' height='128'></body></html>"
html = html.Replace("Box128.png", CompanyLogo.URL)