How to reverse mouse click events?

Asked

Viewed 138 times

1

Hit me a recent doubt, where the click of left button mouse could in a specific case become the right, and vice versa.

Code

var menulist = document.oncontextmenu;

var menu = function(ev) {
    if (ev.button == 0 || ev.button == 1) {
        menulist = new Function("return true;");
            alert('Esquerdo');
    } else {
        if (ev.button == 2 || ev.button == 3) {
            alert('Direito');
        }
    }
}
document.onclick = menu;
document.oncontextmenu = new Function("return false;");

What I really want with this is set the right button as the first, to apply over a link that contains a file to download. Instead of firing a warning for the user to use the right click for Save Link As....

screenshot

Of course, it would be ideal just to play oncontextmenu of right click to the left button when over the link to which it was specified. Then the right click, loses his action at this given moment.

Summary - "I want to know how to apply internal Javascript behaviors to call the oncontextmenu in the onclick."

  • 1

    If you want the user to download because you don’t use the "download" attribute in the link, wouldn’t it be easier? Example: http://answall.com/a/100332/15089

  • @Inkeliz I’ve done method testing download, but even so the video opened inside the browser, IE, it was downloaded into the native player of the browser and did not display the window for the download.

1 answer

1

For his comment:

@Inkeliz I did test with download method, but even so the video opened inside the browser, IE, it was downloaded into the native player of the browser and did not display the download window.

It seems to me that what you want is to ensure that the content will be downloaded to the user’s machine, and not displayed in the browser.

You will not be able to control this by Javascript. It would be a security flaw to be able to control the user’s devices in this way.

What you can do is inform the browser mime-type the content that is accessed by the link address. This is done on the server side. Try to make the MIME type of the file in your link something like "application/octet-stream". This should make all modern browsers understand that content should be downloaded as file/file.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.