Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

document.body.ondrag - Turns off text selection??

Status
Not open for further replies.

econnections

IS-IT--Management
Apr 28, 2006
30
GB
The code below will turn off text selection in IE5+. This is great when you have areas of text in tables that users can double-click get get further info presented on layers becoming visable. The code below stops the text you click on becoming selected (highlighted).

Does anyone knoe thr equivalent in Netscape, please?


document.body.ondrag = function () { return false; };
 
Give the element a class of "unselectable", and then use this CSS:

Code:
.unselectable {
	-moz-user-select: none;
	-khtml-user-select: none;
	user-select: none;
}

This will fix it for any browser that supports the CSS (3?) "user-select" style, as well as Safari, Konqueror, and some Moz-based browsers.

Incidentally, for IE, you should not be using "ondrag" - you should be using "onselectstart", and you could even set the "unselectable" attribute for good measure:

Code:
element.onselectstart = function() { return(false); };
element.setAttribute('unselectable', 'on', 0);

Hope tihs helps,
Dan




Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Dan, thanks.

I've been playing with the above on my test page.



Its currently set to turn-off selection in NS7.2 using unselectable. See first table, middle row. You can double-click in any of the three cells and see windows.status message. If cell is empty the function would create a new calender appointment. If you d-click existing appointment then your allowed to update as shown by message.

The unselectable stops text selection in NS7.2. Is there an IE equivalent, please?
 
The unselectable stops text selection in NS7.2. Is there an IE equivalent, please?

If you read my previous post, you will see I have already shown you this.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top