简体   繁体   English

如何更改鼠标左键单击和右键单击选项?

[英]How to change mouse left click and right click option?

I have some set of HTML files named in sequence. 我有一些按顺序命名的HTML文件。 Is it possible to assign mouse right click to next html page and mouse left click to previous html page and how to do this? 是否可以将鼠标右键单击分配给下一个html页面,将鼠标左键分配给上一个html页面,该怎么做?

This is how we handles the mouse click.. 这就是我们处理鼠标单击的方式。

$('#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');
    }
});
$(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;
    }
    });
  })

And don't forgot add jquery library. 并且不要忘记添加jquery库。

You can also do this with some simple Javascript. 您也可以使用一些简单的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>

This is the traditional way to override left and right clicks. 这是覆盖左键和右键的传统方法。 In the code I'm preventing event propagation of the right-click also so the context menu won't display. 在代码中,我还防止右键单击的事件传播,因此不会显示上下文菜单。

JSFiddle 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";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM