Initialization
Download the DHTMLX Message package as part of the DHTMLX Suite library.
Follow these steps to add a message box to a page:
<!DOCTYPE html>
<html>
<head>
<title>How to Start with DHTMLX Message</title>
<script type="text/javascript" src="../../codebase/suite.js"></script>
<link rel="stylesheet" href="../../codebase/suite.css">
</head>
<body>
<!--optional-->
<div id="message_container"></div>
<script>
// creating DHTMLX Message
dhx.message({
node:"message_container",
text:"This is an error message",
css:"dhx_message--error",
icon:"dxi-close"
});
</script>
</body>
</html>
Include source files
Unpack the downloaded package into your project folder.
Create an HTML file and add the paths to the following DHTMLX Suite files in its header:
suite.jssuite.css
<script type="text/javascript" src="../../codebase/suite.js"></script>
<link rel="stylesheet" href="../../codebase/suite.css">
Create a container
This is an optional step. The default message position is the top-right corner of the screen.
Add a container for Message and give it an id, for example message_container:
<div id="message_container"></div>
Create a message box
Each message box has its own constructor that takes an object with configuration options of message boxes as a parameter. Use one of the following constructors to create a message box:
dhx.message(): {close() => void};— to create a message. The constructor returns an object with theclose()method:
const message = dhx.message({
text:"Message text",
icon:"dxi-clock",
css:"expire",
expire:1000
});
console.log(message); // -> {close: function}
Related sample: Message. Show Message
dhx.alert()— to create an alert message box:
dhx.alert({
header:"Alert Header",
text:"Alert text",
buttonsAlignment:"center"
});
Related sample: Message. Show Alert
dhx.confirm()— to create a confirm message box:
dhx.confirm({
header:"Confirm Header",
text:"Confirm text",
buttons:["decline", "accept"],
buttonsAlignment:"center"
});
Related sample: Message. Show Confirm
dhx.tooltip()— to create a tooltip. The constructor takes two parameters:text— (string) the text of the tooltipconfig— (object) an object with tooltip configuration properties
dhx.tooltip("Current Value 1", {node: "first", position: "center"});
Related sample: Message. Show Tooltip
Configuration properties
The Configuration article describes the properties that you can specify for message boxes and tooltips.