document.selection

G

George Hester

function spawn(ev){
var oSelect = '';
var oFlag = false;
if (ns4 || ns6)
oSelect = document.getSelection();
else if (ie4 || ie5){
if (!ev)
ev = window.event;
oFlag = true;
oSelect = document.selection;
}
alert(oSelect.type);
}
if (oSelect == '')
return;
else{
//stuff
}

In Netscape 4.8 if text is not selected nothing happens which is what I want. Please
disregard the fact that oSelect.type is not Netscape compatible you are really
seeing only a partial of what I am doing.

The issue here comes from this page:

http://www.webreference.com/js/column12/selectionobject.html

where it says, "Therefore, comparing the value of document.selection.type with "None" on Internet Explorer 4.0x,
is equivalent to comparing the value returned by the document.getSelection() method with "" on Navigator 4.0x."

This seems not to be true in IE 5.5. For if I just click on the page which has the above funcion in it
I get "Text" not "None"

So I cannot do this:

if (oSelect == '' || oSelect.type = "None")
return;
else{
//stuff
}

Any suggestions how to fix this? Thanks.
 
R

Richard Cornford

George Hester wrote:
So I cannot do this:

if (oSelect == '' || oSelect.type = "None")
return;
else{
//stuff
}

Any suggestions how to fix this? Thanks.

Desist from writing scripts until you have learnt javascript, everything
you do in the meanwhile will be a bad idea.

Richard.
 
G

George Hester

Hey you are a lovely asshole.

I didn't have it correct. Here it is right.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd" />
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:eek:="urn:schemas-microsoft-com:eek:ffice:eek:ffice"
xmlns="http://www.w3.org/TR/REC-html40"
xmlns:product="urn:products"
xmlns:move="urn:move"
xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<head>
<!--[if gte mso 9]>
<xml>
<o:CustomDocumentProperties>
<o:Approval_x0020_Level msdt:dt="string">Code Review</o:Approval_x0020_Level>
<o:Categories msdt:dt="string">In Process</o:Categories>
<o:Assigned_x0020_To msdt:dt="string">Administrator</o:Assigned_x0020_To>
</o:CustomDocumentProperties>
</xml>
<![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<meta http-equiv="Content-Language" content="en-US" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="MSThemeCompatible" content="Yes" />
<meta http-equiv="imagetoolbar" content="false" />
<meta http-equiv="expires" content="-1" />
<meta name="author" content="George Hester" />
<meta name="owner" content="George Hester" />
<meta name="rating" content="XXX" />
<meta name="robots" content="index,follow" />
<meta name="save" content="favorite" />
<meta name="MS.LOCAL" content="EN-US" />
<meta name="GENERATOR" content="Microsoft FrontPage 6.0" />
<meta name="ProgId" content="FrontPage.Editor.Document" />
<link rel="SHORTCUT ICON" href="/icons/cl6D11.ico" />
<script type="text/javascript" src="/jscripts/initial.js"></script>
<script type="text/javascript">
<!-- Begin
if (ns4 || ns6){
window.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN);
window.onmouseup = spawn;
window.onmousedown = prespawn;
}
else if (ie4 || ie5){
document.onmouseup = spawn;
document.onmousedown = prespawn;
}
function prespawn(ev){
if (ns4 || ns6){
startX = ev.pageX;
startY = ev.pageY;
}
else if (ie4 || ie5){
if (!ev)
ev = window.event;
startX = ev.clientX;
startY = ev.clientY;
}
}
function spawn(ev){
var oSelect = '';
var oRange = '';
var oFlag = false;
if (ns4 || ns6)
oSelect = document.getSelection();
else if (ie4 || ie5){
if (!ev)
ev = window.event;
oFlag = true;
oRange = document.selection.createRange();
oSelect = oRange.text;
}
if (oSelect == '')
return;
else{
spawnwin = window.open('','disp','status=0,height=200,width=300,left=300,top=200');
var oText = (oFlag)?'('+ev.clientX+','+ev.clientY+')<br />':'('+ev.pageX+','+ev.pageY+')<br />';
with (spawnwin.document){
open('text/html');
writeln('<html>\n<head>\n<title>Sub-window</title>\n');
writeln('</head>\n<body>\n');
writeln(oSelect);
writeln('<br />');
writeln('Started at: ');
writeln('('+startX+','+startY+')<br />');
writeln('Ended at: ');
writeln(oText);
writeln('</body>\n</html>');
close()
}
}
}
// End -->
</script>
<style type="text/css">
<!--
body { background-color: #FF0000;
color: #FFCC99; }
a { text-decoration: none; }
-->
</style>
<title>Netscape Mouse Capture</title>
</head>
<body>
<blockquote>Thanks for getting all the way down here. Nobody reads the very bottom of a Web Page huh?
But then if nothing works at a Web Page then it's all a ball of shit anyway. That's the way I am feeling.
Some people say "You're fast.." and others say "I can't get shit from you..." I have tried to access my site
from a Dial-Up connection AOL and Man!, if I had to deal with that I'd think hesterloli is full of crap. So hesterloli is at its wit's end. I want to please everyone but I seem not to be able to.
Let's just say this site was made for Microsoft Internet Explorer using Windows 32-bit, 800 x 600 pixels, 24 bit color, and Cable. If you have all that you may have had fun here.
If you don't you probably wished you had fun here. Keep letting me know about your issues. Some I can fix and most I probably can't.
But I will be a better hesterloli knowing them anyway. Sigh é nora!</blockquote>
</body>
</html>
 
G

Grant Wagner

George said:
spawnwin = window.open('','disp','status=0,height=200,width=300,left=300,top=200');
var oText = (oFlag)?'('+ev.clientX+','+ev.clientY+')<br />':'('+ev.pageX+','+ev.pageY+')<br />';
with (spawnwin.document){
open('text/html');
writeln('<html>\n<head>\n<title>Sub-window</title>\n');
writeln('</head>\n<body>\n');
writeln(oSelect);
writeln('<br />');
writeln('Started at: ');
writeln('('+startX+','+startY+')<br />');
writeln('Ended at: ');
writeln(oText);
writeln('</body>\n</html>');
close()
}

Aside from everything else, this is an incredibly bad item. Assuming for a moment that you are guaranteed a window will even open with your call to window.open(), there is absolutely no guarantee at
all that the document on the new window will be properly constructed or available for method calls milliseconds after the call to window.open(). The call to window.open() is asynchronous, it begins
opening the new window, then the script continues running.

When you call spawnwin.document.open(...), spawnwin.document.write(...), spawnwin.document.close() you have no assurance at all that -typeof spawnwin.document != 'undefined'-.

If you are going to do this, at least use the accepted form:

window.newWindowHtml = [
'<html>',
'<head>',
'<title>Sub-window</title>',
'</head>',
'<body>',
oSelect,
'<br />',
'Started at: ',
'(' + startX + ',' + startY + ')<br />',
'Ended at: ',
oText,
'</body>',
'</html>'
].join('\n');

spawnwin = window.open(
'javascript:eek:pener.newWindowHtml',
'disp',
'status=0,height=200,width=300,left=300,top=200'
);

Now you are guaranteed the text will be written to the new window when the new window is ready to accept it.
 
G

George Hester

Grant Wagner said:
George said:
spawnwin = window.open('','disp','status=0,height=200,width=300,left=300,top=200');
var oText = (oFlag)?'('+ev.clientX+','+ev.clientY+')<br />':'('+ev.pageX+','+ev.pageY+')<br />';
with (spawnwin.document){
open('text/html');
writeln('<html>\n<head>\n<title>Sub-window</title>\n');
writeln('</head>\n<body>\n');
writeln(oSelect);
writeln('<br />');
writeln('Started at: ');
writeln('('+startX+','+startY+')<br />');
writeln('Ended at: ');
writeln(oText);
writeln('</body>\n</html>');
close()
}

Aside from everything else, this is an incredibly bad item. Assuming for a moment that you are guaranteed a window will even open with your call to window.open(), there is absolutely no guarantee at
all that the document on the new window will be properly constructed or available for method calls milliseconds after the call to window.open(). The call to window.open() is asynchronous, it begins
opening the new window, then the script continues running.

When you call spawnwin.document.open(...), spawnwin.document.write(...), spawnwin.document.close() you have no assurance at all that -typeof spawnwin.document != 'undefined'-.

If you are going to do this, at least use the accepted form:

window.newWindowHtml = [
'<html>',
'<head>',
'<title>Sub-window</title>',
'</head>',
'<body>',
oSelect,
'<br />',
'Started at: ',
'(' + startX + ',' + startY + ')<br />',
'Ended at: ',
oText,
'</body>',
'</html>'
].join('\n');

spawnwin = window.open(
'javascript:eek:pener.newWindowHtml',
'disp',
'status=0,height=200,width=300,left=300,top=200'
);

Now you are guaranteed the text will be written to the new window when the new window is ready to accept it.

Thank you Grant. What I have other then the little stuff I made to make it browser compatible with IE came right out of "Netscape Dynamic HTML Developer's Guide." I'm seeing if I can't make my site a little more multi-browser friendly and is comments like yours that I am always eager to read. Thanks again.

George Hester
__________________________________
 
G

George Hester

George Hester said:
George said:
spawnwin = window.open('','disp','status=0,height=200,width=300,left=300,top=200');
var oText = (oFlag)?'('+ev.clientX+','+ev.clientY+')<br />':'('+ev.pageX+','+ev.pageY+')<br />';
with (spawnwin.document){
open('text/html');
writeln('<html>\n<head>\n<title>Sub-window</title>\n');
writeln('</head>\n<body>\n');
writeln(oSelect);
writeln('<br />');
writeln('Started at: ');
writeln('('+startX+','+startY+')<br />');
writeln('Ended at: ');
writeln(oText);
writeln('</body>\n</html>');
close()
}

Aside from everything else, this is an incredibly bad item. Assuming for a moment that you are guaranteed a window will even open with your call to window.open(), there is absolutely no guarantee at
all that the document on the new window will be properly constructed or available for method calls milliseconds after the call to window.open(). The call to window.open() is asynchronous, it begins
opening the new window, then the script continues running.

When you call spawnwin.document.open(...), spawnwin.document.write(...), spawnwin.document.close() you have no assurance at all that -typeof spawnwin.document != 'undefined'-.

If you are going to do this, at least use the accepted form:

window.newWindowHtml = [
'<html>',
'<head>',
'<title>Sub-window</title>',
'</head>',
'<body>',
oSelect,
'<br />',
'Started at: ',
'(' + startX + ',' + startY + ')<br />',
'Ended at: ',
oText,
'</body>',
'</html>'
].join('\n');

spawnwin = window.open(
'javascript:eek:pener.newWindowHtml',
'disp',
'status=0,height=200,width=300,left=300,top=200'
);

Now you are guaranteed the text will be written to the new window when the new window is ready to accept it.

Grant I do have one question though about what you ponted out. I incorporated what you have and it works just as well. But consider the statement with (spwnwin.document). If spawnwin.document was undefined wouldn't the with not have had a true argument; not executed and therefore the window would have had nothing written to it? In other words if the with evaluates true (executes) doesn't that mean the "window is ready to accept it?" Thanks.

George Hester
__________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top