onBeforeContextMenu / onContextMenu / onAfterContextMenu

zoneA
zoneB
zoneC
</> Source
<!DOCTYPE html>
<html>
<head>
	<title>onBeforeContextMenu / onContextMenu / onAfterContextMenu</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
	<link rel="stylesheet" type="text/css" href="../../../codebase/fonts/font_roboto/roboto.css"/>
	<link rel="stylesheet" type="text/css" href="../../../codebase/dhtmlx.css"/>
	<script src="../../../codebase/dhtmlx.js"></script>
	<style>
		#zoneA, #zoneB, #zoneC {
			position: relative;
			float: left;
			width: 100px;
			height: 100px;
			border: 1px solid #c0c0c0;
			background-color: #e7f4ff;
			margin: 100px 0px 0px 50px;
		}
	</style>
	<script>
		var myContextMenu;
		function doOnLoad() {
			myContextMenu = new dhtmlXMenuObject({
				icons_path: "../common/imgs/",
				xml: "../common/dhxmenu.xml"
			});
			myContextMenu.renderAsContextMenu();
			myContextMenu.addContextZone("zoneA");
			myContextMenu.addContextZone("zoneB");
			myContextMenu.addContextZone("zoneC");
			//
			myContextMenu.attachEvent("onBeforeContextMenu", function(zoneId, ev){
				printLog("<b>onBeforeContextMenu</b> zone="+zoneId+"<br>");
				return true; // return false to cancel
			});
			myContextMenu.attachEvent("onContextMenu", function(zoneId){
				printLog("<b>onContextMenu</b> zone="+zoneId+"<br>");
			});
			myContextMenu.attachEvent("onAfterContextMenu", function(zoneId,ev){
				printLog("<b>onAfterContextMenu</b> zone="+zoneId+"<br>");
			});
		}
		function printLog(text) {
			document.getElementById("ta").innerHTML = text+document.getElementById("ta").innerHTML;
			document.getElementById("ta").scrollTop = 0;
		}
	</script>
</head>
<body onload="doOnLoad()">
	<div style=" position: relative; height: 380px;">
		<div id="zoneA">zoneA</div>
		<div id="zoneB">zoneB</div>
		<div id="zoneC">zoneC</div>
	</div>
	<div id="ta" style="width: 500px; height: 160px; border: #909090 1px solid; overflow: auto; font-size: 11px; font-family: Tahoma;"></div>
</body>
</html>

Documentation

Check documentation to learn how to use the components and easily implement them in your applications.