防止在 Paper JS 中显示上下文菜单

Prevent contextual menu to be displayed in Paper JS

我试图阻止右键单击 Paperjs 时显示上下文菜单。我尝试使用以下 JS 代码捕获右键单击事件:

window.addEventListener("contextmenu", function(event){
//document.body.addEventListener("contextmenu", function(event){
    console.log ('Right click');
    
    //event.stopImmediatePropagation();
    event.stopPropagation();
    
    return false;
    //return true;
});

我尝试了很多组合(注释行)。 None 正在工作。我不明白为什么它不起作用,而以下行可以完成工作:

<body oncontextmenu="return false;">

我无法向 <body> 添加属性,所以我想从 JavaScript 添加属性。

这是一个 JSFiddle:https://jsfiddle.net/Imabot/zujxaL95/5/

您正在寻找 event.preventDefault()

window.addEventListener("contextmenu", function(event){
//document.body.addEventListener("contextmenu", function(event){
    console.log ('Right click');
    
    //event.stopImmediatePropagation();
    event.stopPropagation();
    event.preventDefault();
    return false;
    //return true;
});


//var canvas = document.getElementById("canvas");
paper.install(window);
paper.setup(canvas);


var c1 = new Path.Circle(new Point(200, 140), 100);
c1.fillColor = 'red';
c1.visible = true;
html,
body {
    margin: 0;
    overflow: hidden;
    height: 100%;
}


canvas[resize] {
    background:  #ccc;
    cursor: pointer;
    width: 100%;
    height: 100%;
    margin:0;

}
<script src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.12.11/paper-full.min.js"></script>
<canvas id="canvas" resize></canvas>