How to invert mouse click events?

1

I was struck by a recent question, where the% s of the left mouse button could in a specific case turn out to be right , and vice versa. p>

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 mean by this is set the right as the first to apply over a link that contains a file to download . Instead of firing a warning to the web surfer use the right button to Save Link As ... .

Ofcourse,itwouldbeidealjusttoplay%sofrightclickfortheleftbuttonwhenoverthelinkforwhichitwasspecified.Thentherightclick,losesitsactionatanygiventime.

  

Summary-"I want to know how to apply internal JavaScript behaviors to call click in oncontextmenu ."

    
asked by anonymous 03.04.2017 / 11:56

1 answer

1

By your comment:

  

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

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

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

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

    
03.04.2017 / 13:33