본문 바로가기

Programming/HTML

HTML5 Notifications API

	var notificationsEnabled = false;
	
	function initNotifications(){
		if (window.Notification){
			Notification.requestPermission(function(permission) {
				if (permission === 'granted'){
					notificationsEnabled = true;
				} else {
					alert("알림 거절");
				}
			});
		}else{
			alert("브라우저가 AIP를 지원하지 않습니다.I");
		}
	}
	
	function showNotification() {
		if (notificationsEnabled) {
			var notification = new Notification('SSaurel', {
				body : '버튼클릭',
				icon : 'https://www.ssaurel.com/cryptocoins/screenshots/web_hi_res_512.png'
		});
		setTimeout(function() { notification.close(); }, 5000);
	}else {
		alert('Notifications are disabled');
		};
	};