参考链接:
http://www.terrainformatica.com/2006/08/h-smile-core-popup-and-context-menus-htmlayout-and-sciter-engines/

代码示例:

import win.ui;
/*DSG{{*/
var winform = ..win.form( text="HTMLayout 使用右键菜单";bottom=399;parent=...;right=599;border="resizable" )
winform.add( )
/*}}*/

import web.layout;
wbLayout = web.layout(winform)

wbLayout.html = /**
<body>

鼠标右键点击下面的按钮显示右键菜单:<br />
<button class="with-context-menu">右键点击这里</button>

<menu.context id="menuId">
<li id="i1">First item</li>
<li id="i2">Second item</li>
<li id="i3">Third item</li>
<li id="i4">Fourth item</li>
<li>Sub menu
<menu>
<li id="i5">5 item</li>
<li id="i6">6 item</li>
</menu>
</li>
</menu>

</body>
**/

wbLayout.css = /**
.with-context-menu {
context-menu: selector(menu#menuId); /*selector函数的参数是指定右键菜单的CSS选择器*/
}

menu{
width: max-intrinsic; /*内容的最大宽度,可以超出屏幕*/
}
**/

//右键菜单触发下面的函数
wbLayout.onMenuItemClick = function (ltTarget,ltEle,reason,behaviorParams) {

//得到当前弹出菜单的节点
var ltSource = ..web.layout.element( behaviorParams.he )

//ltEle是菜单,ltTarget是点击的菜单项目
winform.msgbox("你点击了菜单 " + ltTarget.innerText )
}

//弹出菜单前触发
wbLayout.onPopupRequest = function (ltTarget,ltEle,reason,behaviorParams) {

//得到当前弹出菜单的节点
var ltSource = ..web.layout.element( behaviorParams.he )
ltSource.innerText = "已弹出菜单"

//ltEle是菜单对象
}

wbLayout.onPopupDismissed = function (ltTarget,ltEle,reason,behaviorParams) {

//得到当前弹出菜单的节点
var ltSource = ..web.layout.element( behaviorParams.he )
ltSource.innerText = "已关闭菜单"

//ltEle是菜单对象
}

winform.show()
win.loopMessage()