在javascript / jQuery中检测ctrl + tab键 [英] detecting ctrl+tab key press in javascript/jQuery

查看:128
本文介绍了在javascript / jQuery中检测ctrl + tab键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,我必须限制用户查看我的网页。在完成页面中的任务之前,不应允许用户按 Ctrl + Tab

I have a requirement wherein I must restrict the user viewing my web page. Users should not be allowed to press Ctrl+Tab before finishing a task in the page.

有没有办法在javascript / jQuery中检测 Ctrl + Tab keypress?

Is there a way to detect Ctrl+Tab keypress in javascript/jQuery?

推荐答案

此代码将检测CTRL + Tab:

This code will detect CTRL+Tab:

$(document).keydown(function(e) {
    if (e.ctrlKey && e.which == 9) {
        alert("CTRL + TAB Pressed")
    }
})

但请注意,CTRL + Tab功能由浏览器控制你不能阻止它,因为这个小提琴将证明你是否有多个标签打开:

Note however that CTRL+Tab functionality is controlled by the browser and you cannot stop it as this fiddle will demonstrate if you have more than one tab open:

示例小提琴

这篇关于在javascript / jQuery中检测ctrl + tab键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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