Web Notification Example

This page requests the user for notification permissions on page load. If the permission is granted, then the user would see a notification with a title, body and icon. Clicking the notification would open a new browser window and close the notification window.

Notification permission for codelooru.com is :

View source of this page for implementation details.

Following javascript snippet is used to show the notifications on this page.


	window.Notification.requestPermission().then(function(result) {
		document.getElementById("permid_cdl").textContent = result;
		notification = new window.Notification('This is Notification Title', 
			{
				body: 'This is the Notification Body. Clicking this notification will open a new window.',
				icon: 'https://www.blogger.com/favicon-image.g?blogID=8051593896124641807'
			}
		);

		notification.onclick = function(event) {
		     window.open('http://www.codelooru.com', 'Codelooru', 'height=400,width=400');
		     this.close();
		};
	});



Comments

Popular posts from this blog

How to Timeout JDBC Queries

Groovy - How to read and write to excel sheets with Groovy?