We are able to intercept a right-click event by adding an event listener to the Spread instance for the Context Menu.
1. Get host element of current workbook
2. Add an event listener for the Context Menu
Step 1: Get the host element of current workbook
Get the host element using SpreadJS’s getHost() method:
window.onload = function (dashboard) {
// Initialize the Spread component with the following line:
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
// Get host element of SpreadJS
spread.getHost();
};
Step 2: Add an event listener for Context Menu
Add an event listener to SpreadJS’s Context Menu, this is because the context menu is triggered when a user right-click.
window.onload = function (dashboard) {
// Initialize the Spread component with the following line:
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
// Get host elemement of SpreadJS
// Add event listener to context menu
spread.getHost().addEventListener("contextmenu", function (e) {
// your code;
console.log("right-clicked");
e.preventDefault();
return false;
});
};
Mackenzie Albitz