Calling a function in your app from HTMLview

NS Basic/App Studio’s HTMLview is a powerful control. It allows you to display HTML formatted content in your app.

HTML can include links to other pages. But it can also be used to execute code. Here’s how to have a link in an HTMLview control call a function in your program.

First, set up a function in your program that you want to call:
Function MyFunction()
    MsgBox "MyFunction called.
End Function

Put this in the innerHTML property of your HTMLview. You can do this in the IDE or at runtime:
<a href='javascript:MyFunction();>
    Text to click
</a>

Now, run it in Chrome or on a device. (The link will display as a link in the IDE, but it won’t do anything). Clicking on the link will bring up the MsgBox.

You can do some amazing stuff with this. You could create an object with much more complexity than the IDE itself lets you do – for example, a scrolling listbox with custom formatting on each line. You could even use BASIC to create your own HTML from your data, then set the HTMLview to show it.