Exposing a method that takes a message and displays that as a notification can be done in one simple block in e.g UI.init():

    Java

    This will expose the notify()-method globally in the window object. Technically it’s thus , but you can call it by simply by notify(). Try entering notify("Hey!") into the Firebug or Developler Tools console, or into the address bar.

    Let’s make a complete example with two arguments, some simple error handling, and namespacing:

    Java

    Using the dotted notation for the method will automatically create those objects in the browser; you’ll call this method like so: com.example.api.notify("Hey!"). You do not have to use a long name like this, though - it’s up to you and your use-case.

    We’re now accepting a second (integer) argument, and using that as type for the Notification.

    Finally, we’ll add a link that will call the function, and work as a Bookmarklet. You can drag the link to your bookmarks bar, and when you invoke it when viewing the application with our exposed -method, you will be prompted for a message that will then be sent to the method. Here is the plain HTML code for creating such a link:

    HTML

    Java