Mar 3 2010

Disable right clicking on images only

There are few instances where disabling someone’s context menu is appropriate. In most cases it’s unnecessary and can even lead to infuriating your visitors.

Here are some ways to target all the image elements on a page while leaving the rest of the hypertext in peace.

JavaScript

Lightweight, no framework required and works well in IE 6, 7, 8, Chrome, FireFox and Safari. Demo »

document.oncontextmenu = context_menu;

function context_menu(e) {
if (!e) var e = window.event;
	var eTarget = (window.event) ? e.srcElement : e.target;

	if (eTarget.nodeName == "IMG") {
		//context menu attempt on top of an image element
		return false;
	}
}

jQuery

Perhaps the prettiest code of the three. Demo »

$(document).ready(function(){
	$(document).bind("contextmenu",function(e){
		if(e.target.nodeName == 'IMG'){
			//context menu attempt on top of an image element
			return false;
		}
	});
});

MooTools

Moo… Demo »

window.addEvent('domready', function() {
	$(document.body).addEvent('contextmenu', function(e) {
		if(e.target.nodeName == 'IMG') {
			//context menu attempt on top of an image element
			return false;
		}
	});
});

Final Thoughts

With a bit more code you can target specific IDs, class names or any number of elemental combinations. Doing so will limit your context menu friendly fire and keep both you and your users in a happy balance.

Cheers!


Feb 26 2010

Best of

Did cavemen listen to books on tape? Find out in the archives...

It’s taken some doing but all my content dating back to 2002 is now available.

Some of my most memorable moments below.

Personal

Work


Feb 21 2010

Mass Effect 2 Soundtrack

Tali'Zorah knows that even in the future, corded headphones are the way to go.

I really enjoyed Mass Effect 2, so much so that I like to imagine talking to people with a choice selector near the bottom of my vision. I usually choose paragon options but I know the usefulness of a well placed renegade response. Be careful with the interrupts though!

Like many good games, I find myself drawn to the soundtrack as a way of reliving our times together. I went searching for it but unfortunately they only released it in MP3 and M4A formats so far.

Call me a snob but I think our future should be filled with upgrades and that means something better than or equal to the sound quality of a Compact Disc.

No worries though because with a bit of patience you too can…

Make your own Mass Effect 2 Soundtrack

These instructions assume you are using the PC version of the game.

Epilogue

Now you can enjoy 508 pieces of Ogg Vorbis encoded music while you wait for EA to release a proper Compact Disc.

Oh and special thanks to Extirpator for the original instructions on how to accomplish this.