jscheuer1
07-02-2005, 04:38 AM
No select text script (http://www.dynamicdrive.com/dynamicindex9/noselect.htm) has a bug in Mozilla. Because the array of tag names to be excluded in NS6+ (Mozilla) is joined into a string before the target tags are tested against it, unintended tags get excluded from the no select text treatment. Here is the array from the demo:
var omitformtags=["input", "textarea", "select"]Here is the string that results from the join method used:
input|textarea|selectHere is the test against that string:
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)Basically, if the tag's lower case name is in that string, it is exempt from the no select treatment. This will include <input>, <textarea> and <select> to be sure but, also <p> and <a> tags. I've come up with a simple remedy which uses the array as is, without joining it to a string. I've also got a method to exclude these same areas under IE6 but, it co-opts the onmouseup event for those elements. Not such a big sacrifice as other events can be used in most cases to work around that. Here is the code:
<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 and cross browser by jscheuer1
***********************************************/
//form tags to omit:
var omitformtags=["input", "textarea", "select"]
function disableselect(e){
for (i = 0; i < omitformtags.length; i++)
if (omitformtags[i]==(e.target.tagName.toLowerCase()))
return;
return false
}
function reEnable(){
return true
}
function noSelect(){
if (typeof document.onselectstart!="undefined"){
document.onselectstart=new Function ("return false")
if (document.getElementsByTagName){
tags=document.getElementsByTagName('*')
for (j = 0; j < tags.length; j++){
for (i = 0; i < omitformtags.length; i++)
if (tags[j].tagName.toLowerCase()==omitformtags[i]){
tags[j].onselectstart=function(){
document.onselectstart=new Function ('return true')
}
tags[j].onmouseup=function(){
document.onselectstart=new Function ('return false')
}
}
}
}
}
else{
document.onmousedown=disableselect
document.onmouseup=reEnable
}
}
window.onload=noSelect;
</script>Hopefully this can be simplified and/or made to append to the onmouseup event in IE for protected tags, rather than co-opting it.
var omitformtags=["input", "textarea", "select"]Here is the string that results from the join method used:
input|textarea|selectHere is the test against that string:
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)Basically, if the tag's lower case name is in that string, it is exempt from the no select treatment. This will include <input>, <textarea> and <select> to be sure but, also <p> and <a> tags. I've come up with a simple remedy which uses the array as is, without joining it to a string. I've also got a method to exclude these same areas under IE6 but, it co-opts the onmouseup event for those elements. Not such a big sacrifice as other events can be used in most cases to work around that. Here is the code:
<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 and cross browser by jscheuer1
***********************************************/
//form tags to omit:
var omitformtags=["input", "textarea", "select"]
function disableselect(e){
for (i = 0; i < omitformtags.length; i++)
if (omitformtags[i]==(e.target.tagName.toLowerCase()))
return;
return false
}
function reEnable(){
return true
}
function noSelect(){
if (typeof document.onselectstart!="undefined"){
document.onselectstart=new Function ("return false")
if (document.getElementsByTagName){
tags=document.getElementsByTagName('*')
for (j = 0; j < tags.length; j++){
for (i = 0; i < omitformtags.length; i++)
if (tags[j].tagName.toLowerCase()==omitformtags[i]){
tags[j].onselectstart=function(){
document.onselectstart=new Function ('return true')
}
tags[j].onmouseup=function(){
document.onselectstart=new Function ('return false')
}
}
}
}
}
else{
document.onmousedown=disableselect
document.onmouseup=reEnable
}
}
window.onload=noSelect;
</script>Hopefully this can be simplified and/or made to append to the onmouseup event in IE for protected tags, rather than co-opting it.