capturing f5 keypress event in javascript using window.event.keyCode in [removed] event is always 0 and not 116

后端 未结 7 895
南方客
南方客 2020-11-29 09:02

i am creating an MVC application.There was a neccessitity to make a variable in a session to null upon closing of the application (i.e. window/tab) but not upon refreshing t

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 09:23

    document.onkeydown = disableF5;
    document.onkeypress = disableF5
    document.onkeyup = disableF5;    
    function disableF5(e) { if ((e.which || e.keyCode) == 116) e.preventDefault(); };
    

提交回复
热议问题