TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Show Desktop Notification Using JavaScript
Devendra Sharma
Jul 20
2016
Code
2.6
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
DesktopNotification.
<
html
>
<
head
>
<
title
>
javascript - Desktop notification
</
title
>
<
script
>
function ShowNotification() {
if (!("Notification" in window)) {
console.log("This browser does not support desktop notification");
}
else if (
Notification.permission
=== "granted") {
var
notification
=
new
Notification("Demo title", {
icon: 'Images/end-chat.png',
body: 'This is a simple desktop notification'
});
}
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (!('permission' in Notification)) {
Notification.permission
= permission;
}
if (
permission
=== "granted") {
var
notification
=
new
Notification("Demo title", {
icon: 'Images/end-chat.png',
body: 'This is a simple desktop notification'
});
}
});
}
}
</
script
>
</
head
>
<
body
>
<
button
onclick
=
"ShowNotification()"
>
Show Notification
</
button
>
</
body
>
</
html
>
It works on all major browser if you run this code using valid site url, you can prefer firefox for quick output.
JavaScript
Show Desktop Notification