PDA

View Full Version : The No select text script



dragonbook
06-09-2005, 08:51 PM
Hi

Abouth the No select text script
Link (http://www.dynamicdrive.com/dynamicindex9/noselect.htm)

I have testet the script and I can see that text surrounded by the < p > < /p> tag isn't protectet by the script in firefox v 1.0.4.

On this page (http://www.dynamicdrive.com/dynamicindex9/noselect.htm)

I can select all the text where you have use the <p> tag.

Is there any way to fix this :confused:

Hope there is an solution :o

Your webside rocks :D

cr3ative
06-10-2005, 06:36 AM
Hi-

All scripts nowadays have lost the ability to disable browser functions with complete success - right-click scripts, etc.

And if anyone wants your text, they can easily view your source code and get it from there, or any other number of places.

cr3

dragonbook
06-10-2005, 09:06 AM
Yes thats true, but I'm not using the script to protect my text....

I have at game seletion on my page, and when some of the games are played it is very annoying if the text and picturs in the game are selectet :(

another thing is that when you try to select the tekst on this page (http://www.dynamicdrive.com/dynamicindex9/noselect.htm) you can do it whith no problem in Firefox !!!!! So it makes me wonder why the text says that the script works in both IE5+ and FF1+

Cause it doesn't worke in FF1+. :(

jscheuer1
06-10-2005, 09:41 AM
You're right, it doesn't work. But, it does work on some things on the page and on a demo I set up here. Try it with your page and see, might do the trick.

dragonbook
06-10-2005, 09:50 AM
I have tried the script on my page, thats how I came to the conclusion that the script don't work in FF.. ;)

jscheuer1
06-10-2005, 06:59 PM
Well, then I'd try the script without its built in selectivity. It is a short script:
<script type="text/javascript">

/***********************************************
* Disable select-text script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

//form tags to omit in NS6+:
var omitformtags=["input", "textarea", "select"]

omitformtags=omitformtags.join("|")

function disableselect(e){
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
return false
}

function reEnable(){
return true
}

if (typeof document.onselectstart!="undefined")
document.onselectstart=new Function ("return false")
else{
document.onmousedown=disableselect
document.onmouseup=reEnable
}

</script>Just remove the red part. That is what is enabling paragrapgh selection (due to the 'p' in the word 'input'). If you have no content on your page which requires exceptions, this should do nicely. If you do have content which requires exceptions be more specific, ex:


<script type="text/javascript">

/***********************************************
* Disable select-text script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

//form tags to omit in NS6+:
var omitformtags=["input", "textarea", "select"]

omitformtags=omitformtags.join("|")

function disableselect(e){
if (e.target.className.toLowerCase()!=='exempt')
return false
}

function reEnable(){
return true
}

if (typeof document.onselectstart!="undefined")
document.onselectstart=new Function ("return false")
else{
document.onmousedown=disableselect
document.onmouseup=reEnable
}

</script>to exempt only elements with the class name 'exempt'.

dragonbook
08-22-2005, 04:45 PM
I don’t know why… but I haven’t seen your last post before now :o It works perfect now THANKS. :D

dragonbook
10-06-2005, 10:56 AM
to exempt only elements with the class name 'exempt'.

I have tried to use your exempt class name like this

<DIV class="exempt">You can mark</DIV>

But I can't mark this text.

Any idear why :confused:

jscheuer1
10-06-2005, 03:29 PM
That is only for Mozilla based browsers, it will not work in IE.

Here is a version of the script that omits tags properly in both browsers:

http://www.dynamicdrive.com/forums/showpost.php?p=11951&postcount=2

dragonbook
10-07-2005, 07:27 AM
Okay thanks...

Is it possible to use something like <DIV class="exempt">You can mark</DIV> around some text I don't want the script to protect ?

While the protected page is loading it is still possible to mark text...... not at big deal but a little strange. Any way to fix this.

jscheuer1
10-10-2005, 03:42 AM
I'll take a look at rewriting it to use a class or id like exempt. The script cannot disable selecting text until the page loads because the script is an onload event. It may not need to be, I'll look into that too.

jscheuer1
10-10-2005, 05:07 AM
OK, this should fit the bill. You can either give the class 'exempt' to the element itself or to its immediate parent. Remember that comments and <br> tags count as parents sometimes. To give you an idea of how to do it, I've included an example. Also, in Mozilla and IE, noselect should take immediate effect. In Mozilla, so should the exempt elements however, exemption cannot take effect in IE until after the page is loaded. Also if you exempt a paragraph or other non-form element in IE, if a user selects its text and continues with the mousedown to select other text, he will have success:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>No Select - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">

/***********************************************
* Disable select-text script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
* Modified here to exclude form tags properly, cross browser by jscheuer1
***********************************************/

function disableselect(e){
if (e.target.className.toLowerCase()=='exempt'||e.target.parentNode.className.toLowerCase()=='exempt')
return;
return false
}

function reEnable(){
return true
}

if (typeof document.onselectstart!="undefined"){
document.onselectstart=new Function ("return false")
window.onload=noSelect;
}
else{
document.onmousedown=disableselect
document.onmouseup=reEnable
}

function noSelect(){
tags=document.all
for (j = 0; j < tags.length; j++)
if (tags[j].className.toLowerCase()=='exempt'){
tags[j].onselectstart=function(){
document.onselectstart=new Function ('return true')
}
if (tags[j].onmouseup!==null){
var mUp=tags[j].onmouseup.toString()
mUp='document.onselectstart=new Function (\'return false\');\n'+mUp.substr(mUp.indexOf('{')+2,mUp.lastIndexOf('}')-mUp.indexOf('{')-3);
tags[j].onmouseup=new Function(mUp);
}
else{
tags[j].onmouseup=function(){
document.onselectstart=new Function ('return false')
}
}
if (tags[j].onmouseout!==null){
var mUp=tags[j].onmouseup.toString()
mUp='document.onselectstart=new Function (\'return false\');\n'+mUp.substr(mUp.indexOf('{')+2,mUp.lastIndexOf('}')-mUp.indexOf('{')-3);
tags[j].onmouseout=new Function(mUp);
}
else{
tags[j].onmouseout=function(){
document.onselectstart=new Function ('return false')
}
}
}
}

</script>
</head>
<body>
<!-- Not Exempt -->
Hi
<!-- Exempt -->
<div class="exempt"><input type="text" name="pop" value="goes"></div>
<!-- Not Exempt -->
<input type="text" name="the" value="weasel">
<!-- Exempt -->
<input class="exempt" type="text" name="all" value="around">
<!-- Exempt -->
<p class="exempt">This Paragraph is Exempt</p>
</body>
</html>

dragonbook
10-10-2005, 07:13 PM
This is perfekt !!!!!
Thanks a billion :D