Notification

Share your advanced knowledge/code with the community.
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Notification

Post by Peter »

just a snippet...

Code: Select all

Procedure ShowNotificationCallback()
  Debug "ShowNotificationCallback()"
EndProcedure

Procedure ShowNotification(Title.s, Message.s, Icon.s = "", Callback = #PB_Ignore)
  
  ! if (!Notification) {    
  Debug "This browser doesn't support desktop notification"
  !   return;
  ! }
  
  ! if (Notification.permission !== "granted") {
  !   Notification.requestPermission();
  ! } else {
  !   var notification = new Notification(v_title, { icon: v_icon, body: v_message, });
  If Callback <> #PB_Ignore
    ! notification.onclick = function () { v_callback() };
  EndIf
  ! }
  
EndProcedure

ShowNotification("Notification title", 
                 "This is a simple desktop notification", 
                 "http://icons.iconarchive.com/icons/paomedia/small-n-flat/64/cat-icon.png",
                 @ShowNotificationCallback())
User avatar
Paul
Posts: 195
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada
Contact:

Re: Notification

Post by Paul »

Using Chrome v68 here ... the page is blank (other than the default blue SpiderBasic background) and the debug window is empty.
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Notification

Post by Peter »

Paul wrote:Using Chrome v68 here ... the page is blank (other than the default blue SpiderBasic background) and the debug window is empty.
please open the console (<F12>) and reload the page. Is there an error message?

Greetings ... Peter
User avatar
Paul
Posts: 195
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada
Contact:

Re: Notification

Post by Paul »

This is the error listed ...


Image
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Notification

Post by Peter »

Paul wrote:Image
ok, this is a 'normal' error message, because SpiderBasic does not create/copy the favicon file. Strange...

that's what it would look like if it worked for you:
Image

(testet with Linux Chrome and Firefox and Windows 2012 Chrome and Firefox (IE doesn't work (of course))
User avatar
Paul
Posts: 195
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada
Contact:

Re: Notification

Post by Paul »

This was annoying me so I went into my Chrome settings and found this (which I know is the port SpiderBasic uses) ...

Image

I deleted it and then ran your code again and this time it worked.
I must have been doing something in the past which caused this entry to exist in Chrome.

Cool code snippet by the way :)
Post Reply