取消頁面右鍵預設選單

瀏覽器滑鼠右鍵相關事件

方法一:於指定html element利用javascript處理 
<div class="container" id="main" oncontextmenu="return false"></div>

透過 oncontextmenu="return false"可取消頁面預設選單功能

 
方法二:直接利用javascript處理
$(function(){

   $("#main").on("mousedown", function(e) {
       console.log(e); // you can inspect the click event

       if (e.which === 3) { // right click = 3, left click = 1
           alert("right click");
       }
    });

   // prevent context menu show up
   var element=$("#main");
   element.on('contextmenu', function(e) {
       e.preventDefault();
   }, false);

});

 

 

 

 

參考:

http://stackoverflow.com/questions/4920221/jquery-js-prevent-right-click-menu-in-browsers

http://stackoverflow.com/questions/16953477/creating-an-event-handler-for-user-right-clicking-and-inspecting-an-element-in-f

遇到問題最可怕的不是被問倒,而是自己選擇逃避