c# - desktop notification using javascript in windows form -


i new , creating simple application in click button , notification on desktop should displayed. doing in windows form c#

the error " nullreferenceexception unhandled

i have 1 button notify in form1. have tried this:

form1.cs

     public form1()             {                 initializecomponent();                 this.load += new eventhandler(form1_load);                 webbrowser1.documentcompleted += new webbrowserdocumentcompletedeventhandler(webbrowser1_documentcompleted);                 webbrowser1.scripterrorssuppressed = true;             }              private void btnnotify_click(object sender, eventargs e)             {                 webbrowser1.document.invokescript("notifyme");             }    private void form1_load(object sender, eventargs e)         {             string currentdirectory = directory.getcurrentdirectory();             webbrowser1.navigate(path.combine(currentdirectory,"htmlpage1.html"));         }          private void webbrowser1_documentcompleted(object sender, webbrowserdocumentcompletedeventargs e)         {             webbrowser1.objectforscripting = this; 

code htmlpage1.html :

<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head>     <meta charset="utf-8" />     <title></title>     <script language="javascript" type="text/javascript">     document.addeventlistener('domcontentloaded', function () {     if (notification.permission !== "granted")     notification.requestpermission();     });      function notifyme() {     if (!notification) {     alert('desktop notifications not available in browser. try chromium.');     return;     }      if (notification.permission !== "granted")     notification.requestpermission();     else {     var notification = new notification('notification title', {     icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',     body: "hey there! you've been notified!",     });      notification.onclick = function () {     window.open("http://stackoverflow.com/a/13328397/1269037");     };      }      }     </script> </head> <body>  </body> </html> 

even if put alert("hi") in notifyme() function, nothing else. still displays same error.

errormsg

you have put html , scripts in debug directory if not automatically placed. thats getcurrentdirectory() hits.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -