Чтобы создать уведомление в Google Chrome, вы можете использовать несколько способов. Вот несколько примеров кода:
Метод 1. Использование API веб-уведомлений
if ("Notification" in window) {
// Check if the browser supports notifications
if (Notification.permission === "granted") {
// If permission is already granted, create a notification
var notification = new Notification("Hello, World!");
} else if (Notification.permission !== "denied") {
// If permission is not denied, request permission from the user
Notification.requestPermission().then(function(permission) {
if (permission === "granted") {
// If permission is granted, create a notification
var notification = new Notification("Hello, World!");
}
});
}
}
Метод 2. Использование Push API
if ("serviceWorker" in navigator && "PushManager" in window) {
// Check if the browser supports service workers and push notifications
navigator.serviceWorker.register("service-worker.js")
.then(function(registration) {
return registration.pushManager.getSubscription()
.then(function(subscription) {
if (subscription) {
// If a subscription exists, create a notification
var title = "Hello, World!";
var options = {
body: "This is a notification from Chrome.",
icon: "icon.png"
};
registration.showNotification(title, options);
} else {
// If no subscription exists, request subscription from the user
return registration.pushManager.subscribe({ userVisibleOnly: true });
}
})
.then(function(subscription) {
// If subscription is obtained, create a notification
if (subscription) {
var title = "Hello, World!";
var options = {
body: "This is a notification from Chrome.",
icon: "icon.png"
};
registration.showNotification(title, options);
}
});
});
}
Метод 3. Использование сторонней библиотеки, например Toastr.js
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="toastr.min.css">
<script src="jquery.min.js"></script>
<script src="toastr.min.js"></script>
<script>
toastr.success("Hello, World!");
</script>
</head>
<body>
</body>
</html>
Это всего лишь несколько примеров. Существуют и другие методы и библиотеки для создания уведомлений в Chrome. Не забудьте включить в HTML-файл необходимые скрипты и разрешения.