Tag Archives: javascript

Hooking up Ctrl+S using JS+Prototypejs

Did you ever find yourself in a position where having Ctrl+S hooked up as an event would be great? Well I have and doing a fast search on google gave me this page OpenJs.com – Keyboard shortcuts.
While this page is great, I needed to have a script that was written in prototypejs, since this is what we use at work (It’s a left over from the early Rails days, where prototypejs was tha bomb).

Since this really isn’t a big thing to do in prototypejs and if you use firebug you could inspect the event object in the dom yourself, I’ll just give you the script:

$(document).observe('keypress', function(e) {
  if(e.charCode==115 && e.ctrlKey) {
    console.log('CTRL+s was called!');

The only important thing to remember, is to call e.stop(), as this prevents the browsers “Save Page” functionality from opening.

Overriding Firebug

The other day at work, I deployed a test release of a product to the test servers, which ofcourse gave some problems… It seems that our CEO’s and other devs didn’t have Firebug installed which caused the app to stop loading. The reason for this is, that I like the console.log() feature, which I use intensively while developing apps.

I then started to uncomment all my console.log() statements before deploying to test servers, but it seemed rather stupid, and the only other alternative was to get the CEO’s and devs to install firebug (and to make them stop using IE for matter). *cough* I decided to find a way to override the console.log() command instead, and I just wanted to share it with you.

try {
	console.log("console.log test"); 
catch(e) {
	console = {
		log: function(a) {
			// blank..

Just put this tiny piece of code at the very top of you file, then it overrides the console.log() command, and all is well! Tested in IE6+7, Opera 9.25 and Firefox (without firebug installed).