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

Notification

by Peter Fri Sep 14, 2018 2:42 pm

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: 30
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada

Re: Notification

by Paul Fri Sep 14, 2018 6:50 pm

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: 525
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: Notification

by Peter Fri Sep 14, 2018 9:41 pm

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: 30
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada

Re: Notification

by Paul Fri Sep 14, 2018 10:08 pm

This is the error listed ...


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

Re: Notification

by Peter Fri Sep 14, 2018 10:24 pm

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: 30
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada

Re: Notification

by Paul Sat Sep 15, 2018 12:57 am

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 :)
Return to Tricks 'n' Tips

Who is online

Users browsing this forum: No registered users and 1 guest