Xojo Web - Logging to the Browser Console
Jan 31, 2019 02:51 PM
Xojo makes coding really easy, but there are times you need to dig in and debug. One way is to use MsgBox which works great when you only need to check a few values. While there are many ways to check values as you debug, Web Apps have the ability to write information to the Browser Console.
Dim i As Integer
For i = 1 To 10
LogToBrowserConsoleLog( "Running Loop Number " + i.ToText )
If you add that code to a Button.Action You should see this in the Browser Console:
The Xojo 'LogToBrowserConsoleLog' Method can be found below along with three helper methods that respectively return a Backslash, Single Quote, and a Double Quote. The three helper method could be removed and have the Chr functions pasted directly into the 'LogToBrowserConsoleLog' method, but we like having those separate since it makes code cleaner an easier to read.
Public Function ChrBackslash() as string
Public Function ChrQuoteDouble() as string
Public Function ChrQuoteSingle() as string
Public Sub LogToBrowserConsoleLog(pMessage as string)
// Escape Single and Double Quotes in the Message
pMessage = ReplaceAll( pMessage, ChrQuoteSingle, ChrBackSlash + ChrQuoteSingle )
pMessage = ReplaceAll( pMessage, ChrQuoteDouble, ChrBackSlash + ChrQuoteDouble )
// Send the Message to the Web Console Log
dim tempContainer as New WebContainer
If this is helpful, get in touch and let us know!
Thanks to Tim Dietrich for suggesting that this was worthy of a blog post!