Source : DocumentationHow to display notification:requestPermission in pop up?
tips: This notification only applies to desktops, does not apply to Android/IOS
The following is an example of the program code
<script>// Notification.requestPermission()
_sdk_run = () => {
if ("Notification" in window) {
Notification.requestPermission(_sdk_permission);
// The Notification interface of the Notifications API is used to configure and display desktop notifications to the user.
}
};
_sdk_permission = (permission) => {
if (permission != "granted") {
// If Access denied
_sdk_permissionError(); // Display Error
return;
} else {
// Access accepted
_sdk_permissionSuccess(); // Display Success
return;
}
};
_sdk_permissionSuccess = () => {
const notification = new Notification("Project Sodik", { // "Project" Sodik Text Display Notif
body: "Sodik: Access approved by you.", // Text Display Notif
icon: "https://avatars.githubusercontent.com/u/111125963?v=4", // Icon Display Notif
}); // create a new notification
setTimeout(() => {
notification.close();
}, 120 * 1000); // close the notification after 60 seconds = 1 minute
notification.addEventListener("click", () => {
window.open(
"https://tamddk.github.io/library/getNotificationInWeb/", // Link Redirect Click
"_blank" // Target Click New Tabs
);
}); // navigate to a URL when clicked
};
_sdk_permissionError = () => {
alert("Sodik: Access not approved by you."); // Display in Alert
};
_sdk_run();
// [open-source] : location:github.com/tamddk/library/tree/main/getNotificationCustomInWeb
</script>