Tutorial: notification.constructor

notification.constructor

Notification represents a window on OpenFin Runtime which is shown briefly to the user on the bottom-right corner of the primary monitor. A notification is typically used to alert the user of some important event which requires his or her attention.

Multiple notifications can be generated at once but will queue if more than 5 are already displayed. Notifications can be dismissed by dragging them to the right with the mouse and can communicate securely with their invoking applications.

For an example of the notification API, please click here.

Options Object

url

The URL of the notification.

message

A message of any primitive or composite-primitive type to be passed to the Notification upon creation.

onClick()

A function that is called when a Notification is clicked.

onClose()

A function that is called when a Notification is closed.

onDismiss()

A function that is called when a Notification is dismissed by swiping to the right.

onError(string reason)

A function that is called when an error occurs. The reason for the error is passed as an argument.

onMessage(various message)

The onMessage function will respond to the messages sent from the notification's sendMessageToApplication method. The function is passed the message, which can be of any primitive or composite-primitive type.

onShow()

A function that is called when a Notification is shown.

timeout

The time for which a notification is displayed. Can be in milliseconds or "never".

Example

In the invoking Application:

var notification = new fin.desktop.Notification({
    url: "notification.html",
    message: "some initial message",
    onClick: function () {
        console.log("clicked");
    },
    onClose: function () {
        console.log("closed");
    },
    onDismiss: function () {
        console.log("dismissed");
    },
    onError: function (reason) {
        console.log("error: " + reason);
    },
    onMessage: function (message) {
        console.log("message: ", message);
    },
    onShow: function () {
        console.log("shown");
    }
});

In notification.html:

<!DOCTYPE html>
<head>
    <script type="text/javascript">
        fin.desktop.main(function () {
            var self = fin.desktop.Notification.getCurrent();

            self.sendMessageToApplication("some message");
        });

        // messages received from the application creating the application
        function onNotificationMessage(message) {
            console.log(JSON.stringify(message));
        }
    </script>
</head>
<body></body>
</html>