

Send the Message to the Web Console Log PMessage = ReplaceAll( pMessage, ChrQuoteDouble, ChrBackSlash + ChrQuoteDouble ) PMessage = ReplaceAll( pMessage, ChrQuoteSingle, ChrBackSlash + ChrQuoteSingle ) Escape Single and Double Quotes in the Message Public Sub LogToBrowserConsoleLog(pMessage as string) Public Function ChrQuoteSingle() as string Public Function ChrQuoteDouble() as string There are more characters that could be added to this like Carriage Returns and Tabs. W3Schools discusses Javascript Special Characters nicely. Replacing the Quotes with a preceding Backslash is called 'escaping' which converts the Quotes into string characters rather than treating them as Quotes to define a string. The "LogToBrowserConsoleLog" Method accepts a string and then replaces each Single Quote and Double Quote with a preceding Backslash. 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. The Xojo 'LogToBrowserConsoleLog' Method can be found below along with three helper methods that respectively return a Backslash, Single Quote, and a Double Quote.

If you add that code to a Button.Action You should see this in the Browser Console: LogToBrowserConsoleLog( "Running Loop Number " + i.ToText ) Here's how to Log some information in a Loop: So, we created a Xojo Method that can be used to make Logging Messages to the Browser Console even easier. However, as developers, we never want to repeat code that can be encapsulated. In a Xojo Web App, you'd call the Javascript console.log command using the ExecuteJavascipt command which is just as simple. You can use Javascript to write to the Console using the Javascript "console.log" command as demonstrated at W3Schools. Once the Console is displayed you may already see messages or it could be blank if nothing has been sent to the Console. Each Browser is different, but just search the web for your particular Browser. In Chome on Mac, you can access the Javascript Console from the Menu Bar > View > Developer > Javascript Console as shown below.
