Skip to content

Instantly share code, notes, and snippets.

@seksenov
Last active August 25, 2024 11:30
Show Gist options
  • Save seksenov/2a08ea82483a0578d1aa to your computer and use it in GitHub Desktop.
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.
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