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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Node Selection

Status
Not open for further replies.

sirlojik

Programmer
Mar 29, 2005
178
UG
How can i prevent a text node from being selectable?
How can i make sure the default cursor stays the same even when over text?

Also, any bored people, go to the link below and tell me if you receive any abnormal window behavior. those divs are set to work like OS windows. the zStacking is a bit dirty so any comments appreciated

---------------------------
ServerOp: LogicSoft
 

Isn't this the same question as your other post, also from today, also in this forum?

thread216-1038900

If not, what is the difference between the two questions?

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 

Again, you'll have to wrap it in a DIV or SPAN, etc, I would say, and then use CSS.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
well, one was about div content selection, this is TEXTNODE selection. big difference.

for div's was solved--using an attribute, text nodes r different and dnt have the same attribute. i was hoping for an answer

---------------------------
ServerOp: LogicSoft
 

You will have to wrap the textNode in a span, div, etc, I would say.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
i did that, the text node is in a div. but still it won't work. is there a way of overriding the default cursor once over a text node?

---------------------------
ServerOp: LogicSoft
 
Solved. here is cross browser approach to prove it.

1) I wrap text in div.
2) Set attribute "UNSELECTABLE" to 'on' for the div.
3) setup an onmousedown handler and cancel default actions.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.divCSS {
	font-family: "Courier New", Courier, mono;
	color: #0000FF;
	border-top-width: 1px;
	border-right-width: 1px;
	border-bottom-width: 1px;
	border-left-width: 1px;
	border-top-style: dotted;
	border-right-style: dotted;
	border-bottom-style: dotted;
	border-left-style: dotted;
	border-top-color: #FFFFFF;
	border-right-color: #000099;
	border-bottom-color: #000099;
	border-left-color: #FFFFFF;
	cursor: default;
	height: auto;
	width: auto;
}
-->
</style>
</head>
<div id = 'textNodeParent' class="divCSS">u cannot select this text. </div>
<script language="JavaScript">
handle_mousedown = function (e)
	{
	if (!e) //IE
		{
		window.event.returnValue = true;
		return 0;
		} 
	else
		{
		e.preventDefault();
		return 0;
		}
	}
	
var divId = document.getElementById('textNodeParent');
if (divId)
	{
	divId["UNSELECTABLE"] = 'on';
	//The above works in most Instances. To be sure it works for all instances
	//even when another div is being dragged over
	if (document.attachEvent)
		{
		divId.attachEvent('onmousedown',handle_mousedown);
		} else
		{
		divId.addEventListener('mousedown',handle_mousedown,false);
		}
	}
</script>
<body>

</body>
</html>

---------------------------
ServerOp: LogicSoft
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top