Olya Bondareva
Olya Bondareva

Reputation: 53

Trapping command+shift+w mousetrap doesn't work

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?

Upvotes: 0

Views: 273

Answers (2)

Adarsh Madrecha
Adarsh Madrecha

Reputation: 7906

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

Upvotes: 0

Cavan Page
Cavan Page

Reputation: 535

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)

Upvotes: 1

Related Questions