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.

The first argument is a Notification Options object (see).

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>