$(window).on("keydown", function (e) { alert(e.keyCode); });
Whas 87key code. I also know what e.ctrlKeyis true, if pressed at that moment Ctrl.
87
e.ctrlKey
true
Is it possible to intercept the Ctrl+ key Wand not close the tab?
I tried:
$(window).on("keydown", function (e) { if (e.keyCode === 87 && e.ctrlKey) { return false; } });
But it seems that in this case, the priority of the browser takes precedence, and the tab is closed.
I am looking for a solution: if this is not possible using JavaScript, perhaps a browser add-on can do this.
You can avoid closing tabs using the "beforeunload" event
$(window).on('beforeunload', function(e) { if(hasUnsaved()) { return 'You have unsaved stuff. Are you sure you want to leave?'; } });
: http://hackab.it/2013/05/page-closing-confirm/
:
$(window).keypress(function(event) { event.preventDefault(); if (event.which == 119 && event.ctrlKey) { alert("Ctrl-W pressed"); } return false; });
, , . , , , . . !
, javascript -, . : , - . - , - . . , , .
- -. " ". beforeunload , , "" "". , , , . beforeunload , .
( ), , preunload, - -, , - . - , , -, , . , - !
beforeunload - , , - , , , , .
, , , , , CTRL + SHIFT + W ( ) , CTRL-W CTRL-TAB . shift, Chrome , CTRL-W.
So, for Windows (not sure what you mean Linux, but you can do the same with xbindkeys):
(Apologies: if the format "code" does not display the following:
^+w:: SetTitleMatchMode RegEx IfWinExist, Google Chrome$ { WinActivate } return
I hope this will be useful for those who are looking for a way to stop Chrome, even after receiving the CTRL-SHIFT-W key combination.
Source: https://habr.com/ru/post/1526299/More articles:Embed / maintain custom CSS in WP8 WebBrowser Control - windows-phoneTwitter POST direct_messages / new api not working - apiHow to send a URL to a friend on Twitter - iosОтобразить список месяца в этом конкретном году в XCode 5 - objective-cОбъединение обходов глубины и ширины в одном запросе cypher - neo4jMySQL query with ranges - sqlSort values by date in mongodb - javaWhy is barcode scanning using the new iOS 7 API so slow? - iosHow to throw std :: invalid_argument error? - c ++https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1526304/how-to-add-multiple-truststore-paths-to-javanetssltruststore&usg=ALkJrhioHYg_z8sDKeypnLscboUCZwCHVAAll Articles