Mr J
09-13-2004, 10:47 AM
When using the following;
In Mozilla:
if I press the Moz button I get the text that I select but if I press the Script button I get "undefined"
In IE:
if I press the IE button I get "[object]" but the script shows the selected text
Can someone educate me here please
Thank you
<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
<SCRIPT>
<!--
moz=document.getElementById&&!document.all
function ShowSelection(){
if(!moz){
oTextRange = document.selection.createRange(); // works in IE
}
else{
oTextRange = window.getSelection() // no work in Moz
}
alert("You highlighted the following text:\n\n"+oTextRange.text);
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<center>
<form>
<input type="button" value="Moz" onClick="alert(window.getSelection())"> works in Moz<BR>
<input type="button" value="IE" onClick="alert(document.selection.createRange())"> no work in IE
<BR><BR>
<input type="button" value="Script" onClick="ShowSelection()"> no work in Moz, works in IE
</form>
<P>Select all or part of this text</P>
</center>
</BODY>
</HTML>
In Mozilla:
if I press the Moz button I get the text that I select but if I press the Script button I get "undefined"
In IE:
if I press the IE button I get "[object]" but the script shows the selected text
Can someone educate me here please
Thank you
<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
<SCRIPT>
<!--
moz=document.getElementById&&!document.all
function ShowSelection(){
if(!moz){
oTextRange = document.selection.createRange(); // works in IE
}
else{
oTextRange = window.getSelection() // no work in Moz
}
alert("You highlighted the following text:\n\n"+oTextRange.text);
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<center>
<form>
<input type="button" value="Moz" onClick="alert(window.getSelection())"> works in Moz<BR>
<input type="button" value="IE" onClick="alert(document.selection.createRange())"> no work in IE
<BR><BR>
<input type="button" value="Script" onClick="ShowSelection()"> no work in Moz, works in IE
</form>
<P>Select all or part of this text</P>
</center>
</BODY>
</HTML>