2013-02-26 161 views
0

我有一些按順序命名的HTML文件集。是否有可能將鼠標右鍵單擊到下一個html頁面,然後鼠標左鍵單擊到之前的html頁面,以及如何執行此操作?如何更改鼠標左鍵單擊和右鍵單擊選項?

+0

請參閱此鏈接 http://stackoverflow.com/questions/1206203/how-to-distinguish-between-left-and-right-mouse-click-with-jquery – KrIsHnA 2013-02-26 04:55:39

回答

1

這就是我們如何處理鼠標點擊..

$('#element').mousedown(function(event) { 
    switch (event.which) { 
     case 1: 
      alert('Left mouse button pressed'); 
      //code to navigate to left page 
      break; 

     case 2: 
      alert('Right mouse button pressed'); 
      //code to navigate to right page 
      break; 
     default: 
      alert('Mouse is not good'); 
    } 
}); 
+0

信貸:http://stackoverflow.com/questions/1206203/how-to-distinguish-between-left-and-right-mouse-click-with-jquery – AlphaMale 2013-02-26 04:58:39

+0

謝謝!知道了:) – 2013-02-26 06:16:51

+0

如果它的工作接受答案和upvote .. – sasi 2013-02-26 06:18:19

0
$(function(){ 
    $(document).mousedown(function(event) { 
    switch (event.which) { 
     case 1: 
      window.location.href = "http://stackoverflow.com" // here url prev. page 
      break; 
     case 3: 
      window.location.href = "http://www.google.com" // here url next. page 
      break; 
     default: 
      break; 
    } 
    }); 
    }) 

而且不要忘了添加jQuery庫。

+0

謝謝!完成它:) – 2013-02-26 06:16:04

0

你也可以用一些簡單的Javascript來做到這一點。

<script type='text/javascript'> 
function right(e){ 
    //Write code to move you to next HTML page 
} 

<canvas style='width: 100px; height: 100px; border: 1px solid #000000;' oncontextmenu='right(event); return false;'> 
    //Everything between here's right click is overridden. 
</canvas> 
+0

謝謝!完成它:) – 2013-02-26 06:17:47

0

這是重寫左右點擊的傳統方式。在代碼中我也阻止了右鍵單擊的事件傳播,所以上下文菜單不會顯示。

JSFiddle

window.onclick = leftClick 
window.oncontextmenu = function (event) { 
    event = event || window.event; 
    if (event.stopPropagation) 
     event.stopPropagation(); 

    rightClick(); 

    return false; 
} 

function leftClick(event) { 
    alert('left click'); 
    window.location.href = "http://www.google.com"; 
} 

function rightClick(event) { 
    alert('right click'); 
    window.location.href = "http://images.google.com"; 
} 
+0

謝謝!完成了:) – 2013-02-26 06:18:42

相關問題