To use dhtmlxMessage you need to have dhtmlx.js and dhtmlx.css files included on the page.
<link rel="STYLESHEET" type="text/css" href="../codebase/dhtmlx.css"> <script src="../codebase/dhtmlx.js" type="text/javascript"></script>
There are 2 ways to initialize the helper:
dhtmlx.message({ type:"confirm-warning", text:"Are you sure you want to do it?" })
dhtmlx.confirm({ title:"Confirm", text:"Continue?" }); //or dhtmlx.alert({ title:"Alert", type:"alert-error", text:"You can't do this" });
The helper can be used in 2 forms:
dhtmlx.alert("some text");
dhtmlx.alert({ type:"alert-error", text:"some text", title:"Error!", ok:"Yes" });
For any type of the message window you can define a custom style to achieve the desired look.
Generally, the appropriate css class is specified through the parameter type: you define a css class and set the parameter to its name.
There are some rules related to setting the 'type' parameter you should keep in mind:
<style type="text/css"> .dhtmlx-myCss{ font-weight:bold !important; color:white !important; background-color:red !important; } </style> ... dhtmlx.message({ type:"myCss", text:"some text" }); //or dhtmlx.confirm ({type:"myCss", text:"some text"}); //or dhtmlx.alert ({type:"myCss", text:"some text"});
To position a message window (alert, confirm box etc.), use the top, left properties of the object constructor:
dhtmlx.confirm({ top:'10px', left:'10px', type:"confirm", text: "Continue?", callback: function(result){ dhtmlx.message("Result: "+result); } });
To position an info box, use the property dhtmlx.message.defPosition.
dhtmlx.message.defPosition="top"; dhtmlx.message("Your data has been successfully saved!");
Note!
If you want to get info box(s) left aligned - add the next style on the page:
<style> .dhtmlx_message_area{ left:5px; right:auto; } </style>
To hide a specified window manually and not to wait while it hides automatically, you can use the dhtmlx.message.hide(winId) method.
dhtmlx.confirm({ id:"myWin", title:"Confirm", text:"Continue?" }); .. dhtmlx.message.hide("myWin");