Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
<!DOCTYPE html>
<title>jsMenus example demo</title>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
<link type='text/css' rel='stylesheet' href='jsMenus.css'>
<script type='text/javascript' src='examples/screenfull.js'> </script>
<script type='text/javascript' src='jsMenus.js'> </script>
<style type="text/css">
.menubar > .menu-item > button { border: solid thin black; }
.menu-item, ul.contextmenu { background-color: lightyellow }
<script type='text/javascript'>
var fileMenu = new Menu();
var editMenu = new Menu();
var viewMenu = new Menu();
var helpMenu = new Menu();
let menuBar = new Menu({ type: 'menubar' });
menuBar.append(new MenuItem({label: 'File', submenu: fileMenu}));
menuBar.append(new MenuItem({label: 'Edit', submenu: editMenu}));
menuBar.append(new MenuItem({label: 'View', submenu: viewMenu}));
menuBar.append(new MenuItem({label: 'Help', submenu: helpMenu}));
var copyItem = new MenuItem({label: "Copy",
accelerator: 'CommandOrControl+C',
click: function() {
if (! document.execCommand("copy", false))
alert("execCommand copy failed");
var pasteItem = new MenuItem({label: "Paste",
accelerator: 'CommandOrControl+V',
click: function() {
if (! document.execCommand("paste", false))
alert("execCommand paste failed");
var showingMenuBar = true;
var showMenuBarItem = new MenuItem({
label: 'Show menubar',
type: 'checkbox',
click: function() {
showingMenuBar = ! showingMenuBar;
Menu.setApplicationMenu(showingMenuBar ? menuBar : null);
checked: true});
fileMenu.append(new MenuItem({
label: 'Clear console',
icon: 'examples/terminal.png',
key: 'D',
modifiers: 'cmd+shift+alt',
tooltip: 'This MenuItem actually does nothing!'}));
fileMenu.append(new MenuItem({
label: "Close",
click: function() {
alert("(close may be disallowed)");
window.close(); }}));
fileMenu.append(new MenuItem({
label: 'Save as...',
enabled: false
var changeTitleMenu = new Menu();
function changeTitle(menuItem) {
document.title = "jsMenus title "+menuItem.label;
// if other code may change document.title add beforeShow handler
changeTitleMenu.append(new MenuItem({label: "demo", type: "radio",
checked: true, click: changeTitle}));
changeTitleMenu.append(new MenuItem({label: "example", type: "radio",
click: changeTitle}));
changeTitleMenu.append(new MenuItem({label: "test", type: "radio",
click: changeTitle}));
viewMenu.append(new MenuItem({
label: "Full Screen",
type: 'checkbox',
checked: false,
beforeShow: function(item) { item.checked = screenfull.isFullscreen; },
click: function() {
editMenu.append(new MenuItem({type: 'separator'}));
editMenu.append(new MenuItem({label: "Change title", submenu: changeTitleMenu}));
var contextMenu = new Menu();
contextMenu.append(new MenuItem({type: 'separator'}));
contextMenu.append(new MenuItem({label: "Change title", submenu: changeTitleMenu}));
const exitFullscreenItem = new MenuItem({
label: "Exit full screen",
visible: false, // hidden unless fullscreen
beforeShow: function(item) { item.visible = screenfull.isFullscreen; },
click: function() {
function loadHandler() {
document.addEventListener('contextmenu', (e) => {
contextMenu.popup(e.clientX, e.clientY);
return false;
window.addEventListener("load", loadHandler, false);
<h1 contenteditable="true">Hello - jsMenus test!</h1>
This is a test of <a href="">jsMenus</a>,
a JavaScript library for creating menus.
Try clicking on the menubar above, or bringing up the context menu
(usually by right-clicking).