当按下alt + tab或Windows + d时,如何在jquery中触发事件? [英] How to fire an event in jquery when alt+tab or windows+d is pressed?

查看:99
本文介绍了当按下alt + tab或Windows + d时,如何在jquery中触发事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我按下alt + tab或Windows + d时,我想触发一个事件.以下是我的代码,当鼠标指针离开浏览器窗口时会发出警报.但是,即使用户按下alt + tab或Windows + D,该事件也应该发生.在这方面,有人可以帮我吗?以下是我的代码供您参考:

I want to fire an event when when alt+tab or windows+d is pressed. Following is my code to give alert when mouse pointer is away from the browser window. But even if user presses alt+tab or Windows+D then also this event should get occur. Can anyone help me oin this regard, please? Folowing is my code for your reference:

<!DOCTYPE html>
<html>
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
    <script>
      var timer;
      $(document).ready(function () {
        $(document).mouseleave(function () {
          //alert("Mouse is away");
          customAlert("your mouse is away");
        });
      });

      function customAlert(customText) {
        $("#popUp").html(customText);
        timer = setInterval(customAlert2, 5000);

        $("#popUp").dialog({
          dialogClass: "no-close",
          buttons: [{
                      text: "OK", click: function () {
                        $(this).dialog("close");
                        clearInterval(timer);
                      }
                    }]
        });
      }

      function customAlert2() {
        location.reload();
        $("#popUp2").dialog({
        dialogClass: "no-close",
        buttons: [{
                  text: "OK", click: function () {
                    $(this).dialog("close");
                  }
                }]
        });
      }


    </script>
  </head>
  <body>
    <h1>My first Javascript program</h1>
    <p>Hello World!</p>
    <div id="popUp" title="First alert message"></div>
    <div id="popUp2" title="Second alert message">Time is over</div>
  </body>
</html>

推荐答案

jwerty 是一个很棒的插件允许您为特定的按键组合创建功能.

jwerty is a great plugin that allows you create functions for specific key combinations.

例如:

jwerty.key('ctrl+shift+P', function () { [...] });

这篇关于当按下alt + tab或Windows + d时,如何在jquery中触发事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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