Skip to content

Instantly share code, notes, and snippets.

@seksenov
Last active October 21, 2016 08:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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