Notifications API

Display browser notifications

IntermediateTopic: Browser API
Back

JavaScript Notifications API Program

This program helps you to learn the fundamental structure and syntax of JavaScript programming.

Try This Code
if ('Notification' in window) {
    Notification.requestPermission().then(permission => {
        if (permission === 'granted') {
            new Notification('Hello', { body: 'This is a notification' });
        }
    });
}
Output
// Shows browser notification

Understanding Notifications API

Notifications API displays browser notifications.

Note: To write and run JavaScript programs, you need to set up the local environment on your computer. Refer to the complete article Setting up JavaScript Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your JavaScript programs.

Table of Contents