通过JavaScript杀死ALT + F4进程 [英] Killing ALT+F4 process through JavaScript

查看:96
本文介绍了通过JavaScript杀死ALT + F4进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我的老板要我杀死ALT + F4进程或者通过JavaScript向用户提示要求它关闭或不通过JavaScript有人试图在应用程序登录时关闭Web应用程序。



我的意思是如果用户已经登录到Web应用程序并且他试图关闭它由ALT + F4然后它不会被关闭(提示)。



我通过Javascript捕获了ALT + F4事件并尝试使用确认框但事件(ALT + F4)也会运行并关闭应用程序。



我正在添加我在这里使用的代码。

Dear Friends,

My Boss have asked me to kill the ALT+F4 process OR to give user the prompt of asking it to close or not through JavaScript if some one tries to close the Web Application while the App is logged in.

I mean if a user has already logged in into the Web Application and if he tries to close it by ALT+F4 then it doesn't get closed (prompt either).

I have captured the ALT+F4 event through Javascript and tried to use the confirm box but the event (ALT+F4) then also runs and closes the application.

I am adding the code i have used here.

<html>
<head>
<title>Detecting browser close in IE</title>


<script type="text/javascript">

var myclose = false;
document.onkeydown = keydown; 

function keydown(evt)
{ 
 if (!evt) 
  evt = event;
  if (evt.altKey && evt.keyCode==115)
  { 
  // ALT+F4 
  //alert("ALT+F4");
    var r=confirm("Do you really want to close the application");
    if(r==true){
      alert("Closing");
    }
    else{
      alert("not closing");
    }
    evt.returnValue = false;
    return false;
  } 
} 

// function keydown(evt)

function ConfirmClose()
{
  if (event.clientY < 0)
  {
    event.returnValue = 'Any message you want';
    setTimeout('myclose=false',100);
    myclose=true;
  }
}

function HandleOnClose()
{
  if (myclose==true) alert("Window is closed");
}

</script>
</head>

<body onbeforeunload="ConfirmClose()" onunload="HandleOnClose()">

<h4>Close browser!</h4>

</body>
</html>





任何帮助都会很明显。



谢谢



Varun Sareen



Any help would be appreciable.

Thanks

Varun Sareen

推荐答案

<html>
<head>
<title>Detecting browser close in IE</title>


<script type="text/javascript">

var myclose = false;
document.onkeydown = keydown; 

function keydown(evt)
{ 
 if (!evt) 
  evt = event;
  if (evt.altKey && evt.keyCode==115)
  { 
    windows.onbeforeunload = Function(){
          return false;
    }
  } 
} 

// function keydown(evt)

function ConfirmClose()
{
  if (event.clientY < 0)
  {
    event.returnValue = 'Any message you want';
  }
}

function HandleOnClose()
{
  if (myclose==true) alert("Window is closed");
}

</script>
</head>

<body onbeforeunload="ConfirmClose()" onunload="HandleOnClose()">

<h4>Close browser!</h4>

</body>
</html>





这是我发现自己的上述问题的解决方案,但现在我想处理浏览器关闭时的控制菜单选项事件。



任何帮助都会很明显。



谢谢



Varun Sareen



This is the solution to my above problem that i found myself but now i want to handle the control menu option event in case of browser closure.

Any help would be appreciable.

Thanks

Varun Sareen


谢谢,但是重新解决方案1,请测试你的代码(或者如果你没有,请说)。



这是window.onbeforeunload而不是windows.onbeforeunload - 没有s。



同时
Thanks, but re Solution 1, please test yr code (or say if you haven't).

It's window.onbeforeunload not windows.onbeforeunload -- no "s".

Also
if (evt.altKey && evt.keyCode==115)

为时已晚......窗口已关闭。

is too late.. window has already shut.


这篇关于通过JavaScript杀死ALT + F4进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆