By pressing the alt-key and click on a url, chrome makes a download. This because of the browsers default alt+click action. How can I prevent that? It should exchange the url.
The code works with other keys (for example x == 88), where the browser has no default actions. But how with the alt-key?
//ALT-key recognition
document.onkeydown=function(){
var keyCode = event.keyCode;
if(keyCode == 18) //alt-key
{
console.log(keyCode);
document.getElementById("hist").setAttribute ('href', "history_by-date.php?wdate=all");
}
}
<div id="history">
<a href="history_by-date.php?wdate=2018&until=2017" id="hist" target="_self" class="a2">should be just a link - not a download (when alt is pressed)</a>
</div><!-- end history -->
Another user here skyline3000 has an interesting article with prevent code, but I bring it not to work. Thanks for any help.
evt.preventDefault();
evt.stopPropagation();
return false;