WinJS using alert() in your JavaScript

WinJS using alert() in your JavaScript

Rate This
  • Comments 2

If you come from JavaScript world you will badly miss the alert() function. However, this habit can be entertained if you declare a function at default.js file. Then it will be accessible in all other pages which are navigated from default.html page.

function alert(message) {
    var msgBox = new Windows.UI.Popups.MessageDialog(message);

Then this code would work,

alert('Welcome back dear Alert');


Leave a Comment
  • Please add 7 and 3 and type the answer here:
  • Post
  • With the major difference that it won't block as alert() does...

  • A much better approach is this. It allows to call multiple alert in row, without MessageDialog.showAsync throwing

    an "Invalid Access" exception.

    var pendingAlerts = [];

    var messageDialogVisible = false;

    showPendingAlerts = function() {

     var pendingAlert;

     if (messageDialogVisible || !pendingAlerts.length) {



     messageDialogVisible = true;

     pendingAlert = pendingAlerts.shift();

     return (new Windows.UI.Popups.MessageDialog(pendingAlert.message)).showAsync().done(function() {

       messageDialogVisible = false;

       if (typeof pendingAlert.callback === "function") {



       return showPendingAlerts();



    window.alert = function(message, callback) {

     window.logger && window.logger.warn && window.logger.warn("alert: " + message);


       message: message,

       callback: callback


     return showPendingAlerts();


Page 1 of 1 (2 items)