JavaScript
--
Questions
--
Followers
Top Experts
Does anybody know a way to disable ALT-F4 key that really works without making any change to the current document or opening a new window, my code works and it disable the key but I have to display an alert and open a new window or it closes the main one. Besides if I push ALT-F4 again while the alert is open it closes the main window too, I would like to do it without making any of this things.
Tahnks in advantage
Javier
P.D.: Here is how I do it.
document.onkeydown=teclas;
function teclas() { Â
var tecla = window.event.keyCode;
var control = window.event.ctrlKey;
var alt = window.event.altKey;
var tipo=event.srcElement.type
if (alt) {
      switch (tecla) {
           // Alt-F4
           case 115:
                 window.event.keyCode=86; Â
                 window.cancelEvent=true;
                 event.cancelBubble=true;
                 event.returnValue=false;
                 event.cancel=true;
                 adios();
                 return false; Â
                 break;
      }
}
}
function adios() {
       // I have to display this alert first
      alert("VEGA :: Opcion no Valida")
       // And open this window too or it wont work
      openCerrar("cerrar.jsp",40
}
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
NO, Why?
To tell you the truth I don't even know what you mean with XXX webadmin
:c)
Javier
And it can be true that you do not serve such pages, but other readers here could use such anoing things, like you ask for, for anyting they want.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Well I'm doing an Intranet application that I want it to work as a client server one and I want to disable user from closing the application without pushing the "Exit" button wich make some validations and invlidates the sesion on the server, the way I told you works but I prefer not to show any message to the client, I do control all the keybord keys, and don let anyone to take any part of the information from the window, I don't know if is wrong or not to do this but if you know the way and don't want to show it here you could sent it to my by mail at ramos_j1@tsm.es, I will appreciate it a lot I've been figuring it out for more than a week and my time cost a lot to my user.
:c)
Javier
Did you test with body attributes:
<body onLoad="initState()" onUnload="checkState()">
In checkState() function you can notify your server side about session termination, for example in a popup window wich ends with self.close().

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
I don't mind deleting the question if nobody is going to answer it. Â But Zvonk, I know what I want to do!!
Thanks anyway for the replays.
Javier
document.onkeydown = function(){
if(!window.event)return
if(window.event.keyCode == 18 || window.event.keyCode == 115)
      {
           alert(":)");
           event.returnvalue=false;
      }
}
</script>
But well done.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
I'm not really sure if it is possible but I think it is or at least I remember I got a page once on the internet that I only coulded close killing the task.
Javier
Is it possible or not?
At least you can save me headaches!!
Javier
Devic, thanks for you effort either, I like that solution but I don't think I'll be able to implement it, onbeforeunload event is fired anytime you change a page and I have 200 JSP on my application, the message will appear everytime I change from one part of the application to another becose I close all windows and open a new one when the user change from one part of it to another.
Well guys I'll slit the points on between you, I guess is the best thing I can do, but if you get to it please let me know it, OK.
Thanks again for the effort.
Javier

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
JavaScript
--
Questions
--
Followers
Top Experts
JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.