Framework7 - Notifications JavaScript API



Description

The notifications can also be added and closed with JavaScript by using the related app methods as shown below −

  • myApp.addNotification(parameters) − It is used to add/show notification, which accepts required object with notification parameters. This method returns HTMLElement with notification element created dynamically.

  • myApp.closeNotification(notificationElement) − It is used to close specified notification, which accepts notificationElement as mandatory parameter and it is a HTMLElement or string of required notification.

The following table shows the notification parameters required when new notification is added −

S.No Parameter & Description Type Default
1

title

It represents the notification title and is equal to notificationTitle app's parameter by default. It is used with iOS theme only.

string
2

subtitle

It represents the notification subtitle and is equal to notificationSubtitle app's parameter, by default. It is used with iOS theme only.

string
3

media

It is the notification media element, which is an HTML string with icon or image. It is equal to notificationMedia app's parameter by default. It is used with iOS theme only.

string
4

hold

It is used to close notification automatically after the specified timeout. It is equal to notificationHold app's parameter by default. It is used with iOS theme only.

number
5

closeIcon

It is disabled to remove close icon from notification. It is equal to notificationCloseIcon app's parameter by default.

boolean true
6

button

It is the material notification button, which accepts 3 properties namely text, color and close. It is used with material theme only.

object
7

closeOnClick

If this is set to true then, notification will be closed after clicking on it. It is equal to notificationCloseOnClick app's parameter by default.

boolean false
8

additionalClass

It is used to add additionally specified CSS class to notification element.

string
9

custom

When you want to use notification with custom HTML layout, this parameter is used. The title, subtitle, media and closeIcon parameters will be ignored while using this parameter.

string
10

onClick

This callback function will be executed after clicking the notification item.

function
11

onClose

This callback function will be executed when notification is closed.

function
framework7_notifications.htm
Advertisements