...

View Full Version : Unselect selected text



soundreamer
01-26-2006, 01:50 PM
function copyit() {
if (bBool) {
tempstore=copiedtext
document.execCommand("Copy")
copiedtext=window.clipboardData.getData("Text");
bBool=false;
}
}
How to unselect the text after the text was copied?

Mr J
01-26-2006, 06:36 PM
Not sure if this is any good


<script type="text/javascript">
<!--

moz=document.getElementById&&!document.all
function unselect_selection(){
if(!moz){
oTextRange = document.selection.createRange()
oTextRange.expand("word")
oTextRange.execCommand("unselect")
}
else{
oTextRange = window.getSelection()
oTextRange.collapseToStart()
}
}
//-->
</script>

<P>Highlight some text then click <a href="#null" onclick= "unselect_selection()"><b>Unselect Selection</b></a>

soundreamer
01-26-2006, 09:46 PM
10x dude...:thumbsup:

felgall
01-26-2006, 09:57 PM
That code will crash Opera. Don't use document.all it has nothing whatever to do with what you need to test for. Test if the feature you need to use is supported not some other irrelevant field.

The only valid use for document.all is:

if (document.all && !document.getElementById) alert('You are one of the two people still using IE4, isn\'t it time you upgraded');

You might use:

moz = !window.execCommand;

which at least tests properly for if the browser isn't Internet Exploder.

abrocket
09-09-2008, 11:59 PM
to unselect text.. just do this:

function unselect(fieldName){
/*
fieldName contains selected text.
to unselect, just remove the text then write it back:
*/
var myfield = document.forms[0].fieldName;
var temp = myfield.value;
myfield.value = "";
myfield.value = temp;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum