Tutorial: notification.constructor

notification.constructor

A notification represents a window in the 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, click here.

Options

ignoreMouseOver

A boolean that will force dismissal even if the mouse is hovering over the notification

message

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

timeout

The timeout for displaying a notification. Can be in milliseconds or "never".

url

The url of the notification.

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 messages sent from notification.sendMessageToApplication. 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.

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");
    }
}, function () {
    console.log("Notification successfully created");  
}, function (error) {
    console.log("Error creating notification:", error);
});

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>