We have a web application that defines a bunch of keyboard shortcuts. One of which is Ctrl + Shift + T. The problem is Microsoft Edge hooks in to this key combo to reopen the previously closed tab or window, and then switch to it.
Reference: Keyboard Shortcuts in Microsoft Edge.
I got playing around a little bit, trying to circumvent this using JavaScript:
<!DOCTYPE html>
<html>
<head>
<title>Ctrl + Shift + T</title>
<script type="text/javascript">
var tKey = 84;
function logKeys(event) {
console.log(event.type + ": " + event.keyCode);
if (event.keyCode === tKey) {
event.preventDefault();
event.stopPropagation();
setTimeout(function() { window.focus(); }, 200);
}
}
document.documentElement.addEventListener("keydown", logKeys);
document.documentElement.addEventListener("keypress", logKeys);
document.documentElement.addEventListener("keyup", logKeys);
</script>
</head>
<body>
</body>
</html>
I was hoping to "cancel" the keyboard events using JavaScript so Edge does not reopen the previously open tab or window. The Edge keyboard shortcut is still taking precedence. In fact, the browser console does not even register a log message for the T key, as denoted by event.keyCode
84.
Maybe my JavaScript chops are getting a little rusty.
Is there a way to prevent Edge from reopening the previous tab or window when pressing Ctrl + Shift + T using JavaScript?