Notificationer non-intrusively notifies users from client-side JavaScript.
Make sure to set the script with type='module'
.
<script type='module'> import * as nf from 'https://joelgrayson.com/software/notificationer/notificationer.js'; //Import notificationer nf.config(); //check full documentation's for config() options nf.notify('Hello world'); nf.notify('Success', 'green'); nf.notify('Confirmation required <button>confirm</button>', 'red'); </script>
Result:
nf.config(options?)
configures the notification space and can only be called once. Below is the options object format:
{ direction:string='bottom-right', //one of the four corners (top-left, top-right, bottom-left, bottom-right) autoclose:boolean=true, //false stops notifications from closing automatically after some time autocloseDuration:number=6000, //seconds before notification closes by itself }
nf.notify(contentHTML: string, color?: string)
nf.close(id: string)
closes the notification with the passed-in id (example below)nf.closeAll()
removes all the notifications.nf.autoclose(onOff: boolean)
sets whether a notification will close automatically or notnf.autocloseDuration(seconds: number)
sets time before a notification closes automatically (default: 6)Try the code sandbox at https://joelgrayson.com/software/notificationer/sandbox.
let errorNotificationId=nf.notify('Error', 'red'); //store notification id nf.close(errorNotificationId); //close notification