Hi itHighway,
Yes its possible. Just set a variable in the javascript to define the word or words you wish to prevent selection of. You could even have an array of words if you wanted to prevent selection of multiple different words. Here's the script for one word:
<script language = "javascript">
function grabText(){
var denySelection = "wrox"
var theText = document.selection
if(theText.type =='Text')
{
var newText = theText.createRange();
}
if (newText.text == denySelection){
document.selection.empty()
}
else{
alert(newText.text)
}
}
</script>
And this is a script that checks for selections across an array, using a for loop:
<script language = "javascript">
function grabText(){
var denySelection = new Array()
var theText = document.selection
denySelection[0] = "Welcome"
denySelection[1] = "to"
denySelection[2] = "wrox"
if(theText.type =='Text')
{
var newText = theText.createRange();
}
for(i =0; i<=2;i++)
{
if (newText.text == denySelection[i])
{
document.selection.empty()
}
}
}
</script>
HTH
Cheers
Joe
|