I recently needed to create a popup that had more than the standard OK button, so after some searching I stumbled upon a script to overwrite the window.alert method with a custom method.
JS Function
- <script type="text/javascript">
- // Overwrite the alert() method
- window.alert = function (sMessage, title, msgtype) {
- if (title == undefined) {title = 'Alert:';}
- if (msgtype == undefined) {msgtype = 'info';}
- //create jqueryui dialog
- var alertDialog = $('<div id="msgDialog"><div>' + sMessage + '</div></div>');
- alertDialog.dialog({
- modal: true,
- title: '<span class="ui-icon ui-icon-'+ msgtype +'" style="margin-right: 0.3em; float: left;"></span> ' + title,
- buttons: {
- Ok: function () {
- $(this).dialog("close");
- }
- }
- });
- return false;
- };
- </script>
Usage:
- alert('At least 1 booking must be selected!!', 'Missing Parameter','alert');
For the third parameter I am passing in the last part of the ui-icon name, ie. alert, info, notice.
That’s about it, this is probably more for me to remember than to blog!