cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <!-- Message of support or unsupport -->
<p class="text"></p>

<button class="btn" data-title="Hello Notification!" data-option="This is Body Message">Notify1</button>
<button class="btn_timer" data-title="Hello again Notification! for second Demo" data-option="This Notification is showing after 5 min when clicking button">Notify2</button>
            
          
!
            
              window.addEventListener('load', function(){
  new notification();
});

var notification = function(){
  this.supportedMessage = 'Notification is supported';
  this.unSupportedMessage = 'Notification is unsupported';
  this.initMessage = document.querySelector('.text');
  this.btn = document.querySelector('.btn');
  this.btnTimer = document.querySelector('.btn_timer');
  this.init();
}

notification.prototype.init = function(){
  var self = this;
  if (('Notification' in window) || ('PushManager' in window)) {
    self.initMessage.textContent = self.supportedMessage;
  } else {
    self.initMessage.textContent = self.unSupportedMessage;
  }
  self.granted();
  self.btn.addEventListener('click', function(event){
      self.notyfy(event.target);
  });
  self.btnTimer.addEventListener('click', function(event){
    window.setTimeout(function(){
      self.notyfy(event.target);
    }, 5000);
  });
};
notification.prototype.granted = function(){
  if (Notification && Notification.permission !== "granted") {
    Notification.requestPermission(function (status) {
      if (Notification.permission !== status) {
        Notification.permission = status;
      }
  	});
  }
};
notification.prototype.getDataTitle = function(target){
  return target.getAttribute('data-title');
};
notification.prototype.getDataOption = function(target){
  return target.getAttribute('data-option');
};
notification.prototype.notyfy = function(target){
  var title = this.getDataTitle(target);
  var body = this.getDataOption(target);
  var options = {
    body: body,
    tag: 'Notification'
  }
  if (Notification && Notification.permission === "granted") {
     new Notification(title, options);
  }
};
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

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

Console