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!


Catching up with FOWA Dublin 2009

20090602-fowa-dublin-2009

Nice of Carsonified to post although their isn’t as much video content as I would like. :(

The following presentations were the best by far.

  • Doing a Start Up in the Real World by David Heinemeier Hansson
    Great talk filled with real advice. No fluff. Watch it then formulate your own plan to make the world a better place. :)
  • 14 Web App Survival Tips by Ryan Carson
    Lots of tips for the aspiring web app creator to help deal with promotion, finance and more.

Revisting FOWA Miami 2009

20090530-fowa-miami-2009

I had the pleasure of attending Future of Web Apps – Miami 2009 earlier this year. It’s a wonderful experience that I highly recommend for anyone in the web industry.

The conferences are put together by nice folks at Carsonified who prove their good intentions by posting videos and slides from each show for anyone who couldn’t make it.

Here are some of my favorites from this year’s event.

  • Order from Chaos: The Future of the Web by Aza Raskin
    Bit of technical problems accompany this great talk about mozilla, open source and how we are moving towards better interfaces for using the web.
  • What is the Future of the Browser? by Dion Almaer & Ben Galbraith
    Great overview of the past, present and future of the web browsers. Very well paced and informative.
  • Keynote by Gary Vaynerchuk
    Need motivation? Gary’s passion is infectious!
  • Scaling your Tech Team by Joe Stump
    Very specific examples and advice for anyone who is interested in or already part of a growing team.

Learning is enjoyment with purpose. :)