0

Is it possible to trap "command+shift+w" in mousetrap? Cause I try to do

Mousetrap. bindGlobal('command+shift+w', (e) => {
    //some actions
});

and my browser(Chrome) window is getting closed. Could I prevent browser from closing on this shortcuts in some way only for specified page of my app?

2 Answers2

1

I tried the following and it worked fine...

Mousetrap.bind('command+shift+w', function(e){ 
     console.log("command shift w")
});

If using windows make sure to use the windows key as opposed to command on mac.

If you are pressing CTRL SHIFT W , then that will shut the browser down. There are certain commands that are restricted to browser use only. See this post for more details javascript capture browser shortcuts (ctrl+t/n/w)

Cavan Page
  • 525
  • 2
  • 12
0

You can pass a 2nd argument to check which key combination fired the event

Mousetrap.bind('command+shift+w', function(e,combo){ 
 console.log(combo);
});

As mention by @Cavan Page, this works

Adarsh Madrecha
  • 6,364
  • 11
  • 69
  • 117