Forum Moderators: phranque

Message Too Old, No Replies

Preventing user from highlighting an image with their mouse?

         

dualfragment

2:56 pm on Aug 3, 2007 (gmt 0)

10+ Year Member



Is there a simple way to prevent a user from highlighting an image with their mouse? I was looking for some type of javascript event such as onHighlight, but I can't seem to find anything.

Basically, when the user highlights an image for a bunch of JS code I have written, it messes the script's look up.

WesleyC

3:32 pm on Aug 3, 2007 (gmt 0)

10+ Year Member



I have a little javascript widget that can prevent this--let me dig it up.

function DisableTextSelection()
{
//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;
}

Now, whenever you want to disable text selection, just call DisableTextSelection();.

dualfragment

3:53 pm on Aug 3, 2007 (gmt 0)

10+ Year Member



Thanks, that helped a ton! Added it to my body.onload event handler and it works like a charm!