Last active
August 25, 2024 11:30
-
-
Save seksenov/2a08ea82483a0578d1aa to your computer and use it in GitHub Desktop.
JavaScript function that displays a toast notification in Universal Windows Apps. For Web Apps, Hosted Web Apps and WebView with Windows Runtume Access.
This file contains 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
function showToast () { | |
if(typeof Windows !== undefined) { | |
var notifications = Windows.UI.Notifications; | |
var template = notifications.ToastTemplateType.toastImageAndText01; | |
var toastXml = notifications.ToastNotificationManager.getTemplateContent(template); | |
var toastTextElements = toastXml.getElementsByTagName("text"); | |
toastTextElements[0].appendChild(toastXml.createTextNode("Toast from Codepen")); | |
var toastImageElements = toastXml.getElementsByTagName("image"); | |
toastImageElements[0].setAttribute("src", "http://assets.codepen.io/assets/social/facebook-default.png"); | |
toastImageElements[0].setAttribute("alt", "red graphic"); | |
var toast = new notifications.ToastNotification(toastXml); | |
var toastNotifier = notifications.ToastNotificationManager.createToastNotifier(); | |
toastNotifier.show(toast); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment