Last active
September 30, 2020 13:16
-
-
Save Gr8Gatsby/3d471150e5b317eb1813 to your computer and use it in GitHub Desktop.
Windows.UI.Notifications JavaScript example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(Windows !== 'undefined' && | |
Windows.UI !== 'undefined' && | |
Windows.UI.Notifications !== 'undefined') { | |
var notifications = Windows.UI.Notifications; | |
//Get the XML template where the notification content will be suplied | |
var template = notifications.ToastTemplateType.toastImageAndText01; | |
var toastXml = notifications.ToastNotificationManager.getTemplateContent(template); | |
//Supply the text to the XML content | |
var toastTextElements = toastXml.getElementsByTagName("text"); | |
toastTextElements[0].appendChild(toastXml.createTextNode(message)); | |
//Supply an image for the notification | |
var toastImageElements = toastXml.getElementsByTagName("image"); | |
//Set the image this could be the background of the note, get the image from the web | |
toastImageElements[0].setAttribute("src", "https://raw.githubusercontent.com/seksenov/grouppost/master/images/logo.png"); | |
toastImageElements[0].setAttribute("alt", "red graphic"); | |
//Specify a long duration | |
var toastNode = toastXml.selectSingleNode("/toast"); | |
toastNode.setAttribute("duration", "long"); | |
//Specify the audio for the toast notification | |
var audio = toastXml.createElement("audio"); | |
audio.setAttribute("src", "ms-winsoundevent:Notification.IM"); | |
//Specify launch paramater | |
toastXml.selectSingleNode("/toast").setAttribute("launch", '{"type":"toast","param1":"12345","param2":"67890"}'); | |
//Create a toast notification based on the specified XML | |
var toast = new notifications.ToastNotification(toastXml); | |
//Send the toast notification | |
var toastNotifier = notifications.ToastNotificationManager.createToastNotifier(); | |
toastNotifier.show(toast); | |
} |
hi, cool gist - helped me a lot
However, I noticed that when i click on a notification my app freezes and i have to close it.
Did that happen to you as well?
Thanks!
Do you know how to put button in the toast?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You know that wasn't intentional :) you could leave out the second selector