...

View Full Version : Preventing users from highlighting images



jmitch18
08-31-2007, 03:39 AM
I want to prevent users from highlighting images on a website I'm currently making just because it seems a bit more professional when they can't accidentally highlight any images used for the design.

I have the following javascript which is supposed to work (found it after some googling):


function DisableSelection()
{
//prevent selecting text in IE
document.onselectstart = new function(){return "false"};

//prevent selecting text in FF
if (window.sidebar)
{
document.onmousedown = DisableText;
document.onclick = EnableText;
}
}

function DisableText(e)
{
return false;
}

function EnableText()
{
return true;
}

I also have onMouseDown="DisableSelection()" inside the tag of each image I don't want them to be able to highlight.

Anyone have any idea why this doesn't work?

Thanks in advance.

felgall
08-31-2007, 03:47 AM
The code in the disable selection function adds the functionality that you want to the entire page when the function is run so by calling it from onmousedown you are only activating it when someone first highlights an image. It is then active for the whole page and not just the images.

jmitch18
08-31-2007, 11:48 AM
Thanks :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum