views:

244

answers:

2

Looks like Opera/Mac does not let you override an action when user pressed ⌘S (the default is, of course, save page). I found out my old script doesn’t work in it. It saves the form contents to server via Ajax.

Here’s an onkey* handler:

key = ev.keyCode
if (!key) key = ev.charCode

if (ev.type == 'keypress' && 115 == key && ev.ctrlKey) return false
if (83 == key && ev.ctrlKey) {
  if (ev.type != 'keypress') save_text ()
  return false
}

The first weirdness of Opera/Mac is that it generates ctrlKey on ⌘ key instead of actual Ctrl key. So in Safari this one works perfectly replacing standard ^S action with mine. But in Opera it ignores ^S completely, since ctrlKey is ⌘ for it, but ⌘S brings the standard Save dialog no matter what you do.

I was trying to actually monitor all the key* event sequence in Opera when I press ⌘S and it’s keydown with keyCode 17, then keypress with keyCode 17, and both happen after I press ⌘. No event at all is generated after I press S.

So it looks like I’m out of luck. Anyone has an idea how to force Opera to let me override ⌘S? :-)

+1  A: 

I'd call it a feature. It shouldn't let you override everything and anything. Next you'll ask how to override Ctrl-Q on Linux so it doesn't close the browser...

Nicolás
A: 

I don't have a Mac handy, but I would expect using preventDefault() from a keydown event (probably the S one, if one is fired) to stop this.

If you go here, tick the "Prevent default" box and press command-s, do you get a save dialog?

http://cross-browser.com/x/examples/key_events.php

hallvors
Yes I do. (* required - at least 15 characters)
Ilya Birman
Seems overriding it doesn't work indeed. Perhaps throw in a report at https://bugs.opera.com/wizard/ ..
hallvors