Manoj G
Manoj G

Reputation: 1806

How to change mouse left click and right click option?

I have some set of HTML files named in sequence. 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?

Upvotes: 0

Views: 2884

Answers (4)

Daniel Imms
Daniel Imms

Reputation: 50189

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

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

Upvotes: 0

Brandon Romano
Brandon Romano

Reputation: 1020

You can also do this with some simple 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>

Upvotes: 0

Petro Gordiyevich
Petro Gordiyevich

Reputation: 307

$(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.

Upvotes: 0

sasi
sasi

Reputation: 4318

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

Upvotes: 1

Related Questions