Click here to Skip to main content
15,911,786 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
<script type="text/javascript" language="javascript">
      window.history.forward(1);
      document.attachEvent("keydown", my_onkeydown_handler);
      function my_onkeydown_handler(e) {
          switch (e.keyCode) {
              case 116: // F5;
                  e.returnValue = false;
                  e.keyCode = 0;
                  window.status = "We have disabled F5";
                  break;
          }
      }
  </script>

This is my code in javascript
but it shows the error "Uncaught TypeError: undefined is not a function"
what is wrong with my code ?
Posted

attachEvent function is only supported in IE. It's a not standard function and you should not use it!
Use addEventListener[^] instead!
 
Share this answer
 
Comments
Madhuri Gamane 1-Dec-14 23:29pm    
Thank you
Kornfeld Eliyahu Peter 2-Dec-14 2:09am    
You are welcome...
Use addEventListener instead of attachEvent(no longer supported).

http://msdn.microsoft.com/en-us/library/ie/ms536343%28v=vs.85%29.aspx[^]

window.history.forward(1);
document.addEventListener("keydown", my_onkeydown_handler);
function my_onkeydown_handler(e) {
switch (e.keyCode) {
case 116: // F5;
e.returnValue = false;
e.keyCode = 0;
window.status = "We have disabled F5";
break;
}
}
 
Share this answer
 
Comments
Madhuri Gamane 1-Dec-14 23:29pm    
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900