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.


Popular Tutorials Pagination System using Ajax, Jquery and PHPSend Friend Request, Accept or Decline Request using Ajax, Jquery and PHPContact Form with Captcha using Ajax, Jquery and PHPWhy Having a FREE website is bad ChoiceBulk image resize with PHPWeb Browser Notification System using JavaScriptIntroduction to php.ini FileTypes of PHP ErrorsProgram Execution Time Limit in PHPTo-do list using PHP and MySQLiMove File from One Folder to the other using PHPHow to change or convert MySQL to MySQLiHow to Upload Video Files using PHP and MySQLiConvert HTML to MS Word Document using PHPEight Reasons Why You Need A Business WebsiteLocal Web Development Server for Windows - XAMPPEasy Shopping Cart using HTML, CSS & JavaScriptComment System using PHP, Ajax and MySQLiAdd, Edit and Delete Record from Database using jQuery and PHPResponsive Contact Form with Captcha using Jquery and PHPUpdate or Delete Multiple Rows using PHPPassword Strength Checker using JqueryFacebook Style Auto Scroll Pagination using jQuery and PHPDomain Checker using Ajax, Jquery and PHPThe if else & elseif Statements in PHPPreview and upload multiple files using ajax and PHPFancy Multiple File Upload using Ajax, Jquery and PHPPagination System without Database using Ajax and PHPUnderstanding Cookies in JavaScript: Create, Read, Update and DeleteSecured Users Access Level System using PHP and MysqlSecure Forgot Password System Using Ajax, Jquery and PHPChat Script Similar to Facebook using Ajax and PHPMake Dynamic XML sitemap using PHPHow to create an animated old letter using an animated penAuto-load User Details on Mouse-Over using Ajax, Jquery and PHPFacebook style Search People and Products using Ajax, Jquery and PHPAuto-suggestion using Ajax and PHPAuto-suggest System using Ajax, Jquery and PHPUsername Availability Checker using Ajax and PHPSimple PHP Anti-Spam Captcha Contact Form Submission

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...