WebHTMLViewer.LoadHTML
From Xojo Documentation
Method
Loads the specified HTML into the WebHTMLViewer.
Notes
If HTML is loaded via https, all links instead the HTML must also be https.
Sample Code
You can load HTML directly from a string like so:
HTMLViewer1.LoadHTML("<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
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.LoadHTML(html)
End If
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.LoadHTML(html)
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>"
HTMLViewer1.LoadHTML(html)
Var html As String = "<html><body>" + js + "</body></html>"
HTMLViewer1.LoadHTML(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)
Me.LoadHTML(html)
Var html As String = "<html><body><img src='Box128.png' width='128' height='128'></body></html>"
html = html.Replace("Box128.png", CompanyLogo.URL)
Me.LoadHTML(html)
See Also
LoadURL method.