ROYACHEN
ROYACHEN

Reputation: 7

How to disable "F4" shortcut key in internet explorer using Javascript?

Application I am going to implement have a shortcut key-f4(Client Request).When I click f4 all the previous url's is listed.I want to disable this..Pls help me....

Upvotes: 1

Views: 1921

Answers (4)

alexP
alexP

Reputation: 3765

document.addEventListener('keydown', function (e) {
    if (e.keyCode == 115) {
        console.log('F4 pressed');
        e.preventDefault();
    }
});

Upvotes: 0

You can use the keydown event of jscript.

$(document).ready(function () {

$(window).keydown(function(event){
 if (event.keyCode == 115) {
            event.preventDefault();
        }
});

});  //Document .ready closed

Upvotes: 1

Michael Unterthurner
Michael Unterthurner

Reputation: 941

<script type="text/javascript">
  document.onkeydown=function(e) {
    e=e||window.event;
    if (e.keyCode === 115 ) {
      e.keyCode = 0;
      alert("This action is not allowed");
      if(e.preventDefault)e.preventDefault();
      else e.returnValue = false;
      return false;
    }
  }
</script>

Upvotes: 2

Amit
Amit

Reputation: 15387

Try this

document.onkeydown = keydown;

function keydown(evt){
  if (!evt) evt = event;
  if (evt.keyCode==115){
    return false;
  }   
}

Upvotes: 3

Related Questions