473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

document.selection

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/colum...ionobject.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.

--
George Hester
__________________________________
Jul 23 '05 #1
5 4186
George Hester wrote:
<snip>
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.
Jul 23 '05 #2
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:o="urn:schemas-microsoft-com:office:office"
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=3 00,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>
--
George Hester
__________________________________
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message news:cm*******************@news.demon.co.uk...
George Hester wrote:
<snip>
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.

Jul 23 '05 #3
George Hester wrote:
spawnwin = window.open('','disp','status=0,height=200,width=3 00,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:opener.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 Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #4
"Grant Wagner" <gw*****@agricoreunited.com> wrote in message news:41***************@agricoreunited.com...
George Hester wrote:
spawnwin = window.open('','disp','status=0,height=200,width=3 00,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:opener.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 Wagner
comp.lang.javascript FAQ - http://jibbering.com/faq


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
__________________________________
Jul 23 '05 #5
"George Hester" <he********@hotmail.com> wrote in message news:o0*******************@twister.nyroc.rr.com...
"Grant Wagner" <gw*****@agricoreunited.com> wrote in message news:41***************@agricoreunited.com...
George Hester wrote:
spawnwin = window.open('','disp','status=0,height=200,width=3 00,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:opener.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 Wagner
comp.lang.javascript FAQ - http://jibbering.com/faq


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
__________________________________
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: lawrence | last post by:
I'm a beginner with Javascript and especially cross-browser Javascript. I got this working in IE, but not in Netscape 7. It seems like, in Netscape, every time I click on a button, the focus shifts...
1
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
15
by: lawrence | last post by:
Is this the correct way to test for a method before I use it? createRange() is, I believe, an IE only method. function wrapSelectionInTag(selection, tag) { if (document.selection.createRange)...
3
by: svdh2 | last post by:
I have been looking at a problem the entire week in access, I have still not been able to find a solution. Hope that you could maybe tell where to look Concerns the link between Access and Word....
0
by: volume | last post by:
Hi all, In an effort to try to impress the boss, I would like to log accounting information to an Excel spreadsheet using C# and .NET. This would be a mockup only, not a real solution - yet! We...
3
by: Adam Faulkner via DotNetMonster.com | last post by:
I want to create a method within a class that opens a Microsoft Word 2000 Document and has the facility to Create a new word document and then extract a Page that exists within the original Word...
1
by: Adam Faulkner via DotNetMonster.com | last post by:
I had a problem before extracting pages from an existing word document and then inserting the content into a new word document. The following code below works with Microsoft Word 2000 Function...
0
southoz
by: southoz | last post by:
Good ay all , I'm fairly new to access(a little over 5 weeks now). Since I'v started I have picked up a lot of useful information from forums such as this and in doing so will share that information...
0
by: PracticalApps | last post by:
I looked to find a canned solution to create a Word document in my application and just couldn't find anything that just gets to the point. I would think, and I may be making too strong of an...
1
by: mrsgwen90 | last post by:
I have an access application with a vba backend and it opens a word document to enter information and then print the word document and should close it. I keep getting an error on the line...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.