I’ve seen several examples on this site of how to disable the browser context menu for FireFox, etc; but none of these are working on the current version of FireFox that I am using:
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
The examples I have seen involve the use of DHTMLxEvent in the following ways:
To disable browser context menu for the entire body of the document:
dhtmlxEvent(document.body,"contextmenu",function(e){
(e||event).cancelBubble=true;
return false;
});
To disable browser context menu for the grid object:
dhtmlxEvent(gridhandle.entBox,"contextmenu",function(e){
(e||event).cancelBubble=true;
return false;
});
I’ve tried both of the above with no luck. The browser context menu pops up regardless; and it obscures my custom context menu.
Another possibility that I have tried, which works for disabling the browser context menu; but also disables the custom DHTMLxMenu context menu is:
function OnContextMenuEvent() {return false;}
window.oncontectmenu=OnContextMenuEvent();
Here is some of my code, so you can reconstruct this, in case it doesn’t happen on your end:
/**
* Class: ClientInsurance
*
* Purpose: Construct the ClientInsurance object
*
* @param insuranceGrid_id - id of the grid to which to bind the client insurance grid
* @param blankProviderString - string to use for the dynamically created blank provider row
* @param clientId - id of the client being edited
*/
function ClientInsurance(insuranceGrid_id, blankProviderString, clientId) {
this.insurancegrid_id = insuranceGrid_id;
this.insurancegrid = null;
this.blankProviderString = blankProviderString;
this.clientId = clientId;
this.dhtmlxMenuIconPath = 'dhtmlx_build91111/dhtmlxMenu/imgs/';
this.dhtmlxImgUrl = 'dhtmlx_build91111/imgs/';
this.contextMenu = null;
}
/**
* INITIALIZE THE ClientInsurance OBJECT
*
* Purpose: This function instantiates the client insurance grid and context menu.
*/
ClientInsurance.prototype.init=function() {
this.initClientInsuranceGrid(); // INITIALIZE THE CLIENT INSURANCE GRID
this.initClientInsuranceGridContextMenu(); // INITIALIZE THE RIGHT-CLICK MENU
}
/**
* INITIALIZE THE GRID CONTAINING THE INSURANCE SELECTIONS FOR THE CLIENT
*
* Purpose: This function instantiates and configures the client insurance grid
*/
ClientInsurance.prototype.initClientInsuranceGrid=function() {
this.insurancegrid = new dhtmlXGridObject(this.insurancegrid_id);
newId = 0; // sentinal for new rows
this.insurancegrid.imgURL = this.dhtmlxImgUrl;
this.insurancegrid.setSkin("light");
this.insurancegrid.init();
dhtmlxEvent(this.insurancegrid,"contextmenu",function(e){
(e||event).cancelBubble=true;
return false;
});
this.insurancegrid.enableLightMouseNavigation(false);
this.insurancegrid.loadXML('clientEdit.do?action=getInsuranceXML&cid=' + this.clientId);
this.insurancegrid.parentObject = this;
// WHEN A CELL IS EDITED, ADD A BLANK ROW BELOW TO ALLOW FOR ADDITIONAL PROVIDERS
this.insurancegrid.attachEvent("onEditCell", function(stage,rId,cInd,nValue,oValue){
if(cInd == 0 && oValue == this.parentObject.blankProviderString) {
console.debug('blank provider row used, creating new row');
this.addRow("new_" + newId++ ,this.parentObject.blankProviderString + ",,");
}
return nValue;
});
}
/**
* INITIALIZE THE RIGHT-CLICK CONTEXT MENU FOR THE CLIENT INSURANCE GRID
*
* Purpose: This function instantiates and configures the context menu for the
* client insurance grid.
*/
ClientInsurance.prototype.initClientInsuranceGridContextMenu=function() {
this.contextMenu = new dhtmlXMenuObject();
this.contextMenu.renderAsContextMenu();
// this.contextMenu.addContextZone(this.insurancegrid_id);
this.contextMenu.setIconsPath(this.dhtmlxMenuIconPath);
this.contextMenu.addNewChild(this.contextMenu.topId, 0, "delete", "Delete", false );
this.contextMenu.addNewChild(this.contextMenu.topId, 1, "new", "Add New Provider", false);
this.insurancegrid.enableContextMenu(this.contextMenu);
this.contextMenu.parentGrid = this.insurancegrid;
this.contextMenu.parentObject = this;
// handle clicks on the menu items
this.contextMenu.attachEvent("onClick", function(id, zoneId, casState) {
var data = this.parentGrid.contextID.split("_");
rid = data[0];
// delete option selected
if(id == 'delete') {
//var rid = insurancegrid.getSelectedRowId();
alert("current row selection is: " + rid);
// don't allow the user to delete the "blank" row
if(this.parentGrid.cells(rid, 0).getValue() != this.parentObject.blankProviderString) {
this.parentGrid.deleteRow(rid);
}
}
});
}
Here are the relevant pieces of the html document which call the javascript:
<div id="insuranceGrid" style="overflow:hidden;height: 120px;width: 600px;" ></div>
<script type="text/javascript">
var clientInsurance = new ClientInsurance('insuranceGrid', '-- select a provider --', '244454711');
clientInsurance.init();
</script>