Loading.......
Loading...

Web Browser Notification System using JavaScript

Posted on 24th October, 2019
WEB BROWSER NOTIFICATION SCRIPT JAVASCRIPT NOTIFICATION SCRIPT NEW UPDATE SCRIPT
The Web has become increasingly interactive and the need to implement a system that allows web pages to control the display of notifications to the end user has become a necessity to enhance user experience.

This is a JavaScript web browser notification system that allows you to push your website articles or latest updates to your end users.

You may have wondered how websites such as Facebook, Twitter, etc pop-up their notification window on your browser where you are asked to ALLOW or DENY them the permission to show you notifications.

The few lines of JavaScript codes in this tutorial will demonstration to you how notification system like that are implemented

JavaScript Code

<script type="text/javascript">

// These are the lastest updates we want to show in our notification window - You can fetch this data from the database as you wish and create a json array as shown below
var latest_updates = [
["Comment System using PHP, Ajax and MySQLi", "Recommended By Vasplus Blog!", "Recommended By Vasplus Blog!", "https://www.vasplus.info/tutorial/7/comment-system-using-php-ajax-and-mysqli"],

["Easy Shopping Cart using HTML, CSS & JavaScript", "Recommended By Vasplus Blog!", "https://www.vasplus.info/tutorial/6/easy-shopping-cart-using-html-css-javascript"],

["Local Web Development Server for Windows - XAMPP", "Recommended By Vasplus Blog!", "https://www.vasplus.info/tutorial/5/local-web-development-server-for-windows-xampp"],

["Convert HTML to MS Word Document using PHP", "Recommended By Vasplus Blog!", "https://www.vasplus.info/tutorial/14/convert-html-to-ms-word-document-using-php"],

["How to Upload Video Files using PHP and MySQLi", "Recommended By Vasplus Blog!", "https://www.vasplus.info/tutorial/13/how-to-upload-video-files-using-php-and-mysqli"],

["How to change or convert MySQL to MySQLi", "Recommended By Vasplus Blog!", "https://www.vasplus.info/tutorial/10/how-to-change-or-convert-mysql-to-mysqli"],

["Move File from One Folder to the other using PHP", "Recommended By Vasplus Blog!", "https://www.vasplus.info/tutorial/9/move-file-from-one-folder-to-the-other-using-php"],

["To-do list using PHP and MySQLi", "Recommended By Vasplus Blog!", "https://www.vasplus.info/tutorial/8/to-do-list-using-php-and-mysqli"],

["Program Execution time Limit in PHP", "Recommended By Vasplus Blog!", "https://www.vasplus.info/tutorial/4/program-execution-time-limit-in-php"],
["Introduction to php.ini File", "Recommended By Vasplus Blog!", "https://www.vasplus.info/tutorial/3/types-of-php-errors"],

["Update or Delete Multiple Rows using PHP", "Recommended By Vasplus Blog!", "https://www.vasplus.info/tutorial/2/introduction-to-phpini-file"]];


function vpb_notification_system( title, description, link_to_application ) 
{
	 // Let's check if the browser supports notifications
	if (!("Notification" in window)) 
	{
		console.log('Oops!!! Your browser does not support desktop notification system!'); 
		return;
	}
	// Let's check whether notification permissions have already been granted
	else if (Notification.permission === "granted")
	{
		// If it's okay let's create a notification
		var notification_system = new Notification(title, { icon:'http://www.vasplus.info/logo/logo.jpg', body: description });
		notification_system.onclick = function () 
		{
			window.open( link_to_application );      
		};
		notification_system.onclose = function () 
		{
			console.log('Notification has been closed');
		};
		//Notification.requestPermission();
	}
	// Otherwise, we need to ask the user for permission
	 else if (Notification.permission !== "denied") 
	 {
		Notification.requestPermission().then(function (permission) 
		{
		  // If the user accepts, let's create a notification
		  if (permission === "granted") 
		  {
			  // If it's okay let's create a notification
				var notification_system = new Notification(title, { icon:'http://www.vasplus.info/logo/logo.jpg', body: description });
				notification_system.onclick = function () 
				{
					window.open( link_to_application );      
				};
				notification_system.onclose = function () 
				{
					console.log('Notification has been closed');
				};
		  }
		});
	  }
}

function vpb_show_notifications()
{ 
	var randomized = Math.floor((Math.random() * 14) + 1); // Randomize total application we want to show in the notification
	
	var title = latest_updates[randomized]['0'];
	var description = latest_updates[randomized]['1'];
	var link_to_application = latest_updates[randomized]['2'];
	
	vpb_notification_system(title, description, link_to_application );
}
window.onload = function() {
	vpb_show_notifications(); // Show notification first on page load
	settimeout(vpb_show_notifications, 100000); // Show new notification every 10 seconds
};
</script>
This notification API supports all modern web browsers

The script is very easy to understand and customize with programming code comments to ease usability.

To see the system in action, please click on the Live Demo button below and click on the Download button to download the script if you like it.

Thank You!
The Vasplus Team.

Post Comment
Press Enter to send
No comment yet.

Submit your Job or Project Today!

We can help you turn your idea into reality, take over your existing project, or extend your current development team.

Submit your idea job or project below and we will follow up with you shortly.

OUR OBJECTIVE

Our objective is to reach a place where our services will be highly regarded by businesses from various industrial domains for building their innovative busines solutions with our cutting-edge technological expertise, interactive designs and uncompromised quality.

OUR MISSION

We aspire to help businesses ranging from startups to enterprises, who reach out to us with their requirements, in achieving great lengths, expanding their reach, upscaling their products, and generate a large user-base with our outstanding and cost-effective services.

Please Wait....
Please Wait...