document.selection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • George Hester

    document.selection

    function spawn(ev){
    var oSelect = '';
    var oFlag = false;
    if (ns4 || ns6)
    oSelect = document.getSel ection();
    else if (ie4 || ie5){
    if (!ev)
    ev = window.event;
    oFlag = true;
    oSelect = document.select ion;
    }
    alert(oSelect.t ype);
    }
    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:



    where it says, "Therefore, comparing the value of document.select ion.type with "None" on Internet Explorer 4.0x,
    is equivalent to comparing the value returned by the document.getSel ection() 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
    _______________ _______________ ____
  • Richard Cornford

    #2
    Re: document.select ion

    George Hester wrote:
    <snip>[color=blue]
    > So I cannot do this:
    >
    > if (oSelect == '' || oSelect.type = "None")
    > return;
    > else{
    > //stuff
    > }
    >
    > Any suggestions how to fix this? Thanks.[/color]

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

    Richard.


    Comment

    • George Hester

      #3
      Re: document.select ion

      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:sc hemas-microsoft-com:vml"
      xmlns:o="urn:sc hemas-microsoft-com:office:offi ce"
      xmlns="http://www.w3.org/TR/REC-html40"
      xmlns:product=" urn:products"
      xmlns:move="urn :move"
      xmlns:msdt="uui d:C2F41010-65B3-11d1-A29F-00AA00C14882">
      <head>
      <!--[if gte mso 9]>
      <xml>
      <o:CustomDocume ntProperties>
      <o:Approval_x00 20_Level msdt:dt="string ">Code Review</o:Approval_x002 0_Level>
      <o:Categories msdt:dt="string ">In Process</o:Categories>
      <o:Assigned_x00 20_To msdt:dt="string ">Administrator </o:Assigned_x002 0_To>
      </o:CustomDocumen tProperties>
      </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="MSThemeC ompatible" content="Yes" />
      <meta http-equiv="imagetoo lbar" 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="favori te" />
      <meta name="MS.LOCAL" content="EN-US" />
      <meta name="GENERATOR " content="Micros oft FrontPage 6.0" />
      <meta name="ProgId" content="FrontP age.Editor.Docu ment" />
      <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.captureE vents(Event.MOU SEUP|Event.MOUS EDOWN);
      window.onmouseu p = spawn;
      window.onmoused own = prespawn;
      }
      else if (ie4 || ie5){
      document.onmous eup = spawn;
      document.onmous edown = 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.getSel ection();
      else if (ie4 || ie5){
      if (!ev)
      ev = window.event;
      oFlag = true;
      oRange = document.select ion.createRange ();
      oSelect = oRange.text;
      }
      if (oSelect == '')
      return;
      else{
      spawnwin = window.open('', 'disp','status= 0,height=200,wi dth=300,left=30 0,top=200');
      var oText = (oFlag)?'('+ev. clientX+','+ev. clientY+')<br />':'('+ev.pageX +','+ev.pageY+' )<br />';
      with (spawnwin.docum ent){
      open('text/html');
      writeln('<html> \n<head>\n<titl e>Sub-window</title>\n');
      writeln('</head>\n<body>\n ');
      writeln(oSelect );
      writeln('<br />');
      writeln('Starte d at: ');
      writeln('('+sta rtX+','+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>Netsca pe Mouse Capture</title>
      </head>
      <body>
      <blockquote>Tha nks 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" <Richard@litote s.demon.co.uk> wrote in message news:cmbcqc$t4p $1$830fa17d@new s.demon.co.uk.. .[color=blue]
      > George Hester wrote:
      > <snip>[color=green]
      > > So I cannot do this:
      > >
      > > if (oSelect == '' || oSelect.type = "None")
      > > return;
      > > else{
      > > //stuff
      > > }
      > >
      > > Any suggestions how to fix this? Thanks.[/color]
      >
      > Desist from writing scripts until you have learnt javascript, everything
      > you do in the meanwhile will be a bad idea.
      >
      > Richard.
      >
      >[/color]

      Comment

      • Grant Wagner

        #4
        Re: document.select ion

        George Hester wrote:
        [color=blue]
        > spawnwin = window.open('', 'disp','status= 0,height=200,wi dth=300,left=30 0,top=200');
        > var oText = (oFlag)?'('+ev. clientX+','+ev. clientY+')<br />':'('+ev.pageX +','+ev.pageY+' )<br />';
        > with (spawnwin.docum ent){
        > open('text/html');
        > writeln('<html> \n<head>\n<titl e>Sub-window</title>\n');
        > writeln('</head>\n<body>\n ');
        > writeln(oSelect );
        > writeln('<br />');
        > writeln('Starte d at: ');
        > writeln('('+sta rtX+','+startY+ ')<br />');
        > writeln('Ended at: ');
        > writeln(oText);
        > writeln('</body>\n</html>');
        > close()
        > }[/color]

        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.docume nt.open(...), spawnwin.docume nt.write(...), spawnwin.docume nt.close() you have no assurance at all that -typeof spawnwin.docume nt != 'undefined'-.

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

        window.newWindo wHtml = [
        '<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:ope ner.newWindowHt ml',
        'disp',
        'status=0,heigh t=200,width=300 ,left=300,top=2 00'
        );

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

        --
        Grant Wagner <gwagner@agrico reunited.com>
        comp.lang.javas cript FAQ - http://jibbering.com/faq

        Comment

        • George Hester

          #5
          Re: document.select ion

          "Grant Wagner" <gwagner@agrico reunited.com> wrote in message news:41895B20.F 2F1761D@agricor eunited.com...[color=blue]
          > George Hester wrote:
          > [color=green]
          > > spawnwin = window.open('', 'disp','status= 0,height=200,wi dth=300,left=30 0,top=200');
          > > var oText = (oFlag)?'('+ev. clientX+','+ev. clientY+')<br />':'('+ev.pageX +','+ev.pageY+' )<br />';
          > > with (spawnwin.docum ent){
          > > open('text/html');
          > > writeln('<html> \n<head>\n<titl e>Sub-window</title>\n');
          > > writeln('</head>\n<body>\n ');
          > > writeln(oSelect );
          > > writeln('<br />');
          > > writeln('Starte d at: ');
          > > writeln('('+sta rtX+','+startY+ ')<br />');
          > > writeln('Ended at: ');
          > > writeln(oText);
          > > writeln('</body>\n</html>');
          > > close()
          > > }[/color]
          >
          > 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.docume nt.open(...), spawnwin.docume nt.write(...), spawnwin.docume nt.close() you have no assurance at all that -typeof spawnwin.docume nt != 'undefined'-.
          >
          > If you are going to do this, at least use the accepted form:
          >
          > window.newWindo wHtml = [
          > '<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:ope ner.newWindowHt ml',
          > 'disp',
          > 'status=0,heigh t=200,width=300 ,left=300,top=2 00'
          > );
          >
          > 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.javas cript FAQ - http://jibbering.com/faq
          > [/color]

          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
          _______________ _______________ ____

          Comment

          • George Hester

            #6
            Re: document.select ion

            "George Hester" <hesterloli@hot mail.com> wrote in message news:o0did.3986 8$JS4.16933@twi ster.nyroc.rr.c om...
            "Grant Wagner" <gwagner@agrico reunited.com> wrote in message news:41895B20.F 2F1761D@agricor eunited.com...[color=blue]
            > George Hester wrote:
            > [color=green]
            > > spawnwin = window.open('', 'disp','status= 0,height=200,wi dth=300,left=30 0,top=200');
            > > var oText = (oFlag)?'('+ev. clientX+','+ev. clientY+')<br />':'('+ev.pageX +','+ev.pageY+' )<br />';
            > > with (spawnwin.docum ent){
            > > open('text/html');
            > > writeln('<html> \n<head>\n<titl e>Sub-window</title>\n');
            > > writeln('</head>\n<body>\n ');
            > > writeln(oSelect );
            > > writeln('<br />');
            > > writeln('Starte d at: ');
            > > writeln('('+sta rtX+','+startY+ ')<br />');
            > > writeln('Ended at: ');
            > > writeln(oText);
            > > writeln('</body>\n</html>');
            > > close()
            > > }[/color]
            >
            > 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.docume nt.open(...), spawnwin.docume nt.write(...), spawnwin.docume nt.close() you have no assurance at all that -typeof spawnwin.docume nt != 'undefined'-.
            >
            > If you are going to do this, at least use the accepted form:
            >
            > window.newWindo wHtml = [
            > '<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:ope ner.newWindowHt ml',
            > 'disp',
            > 'status=0,heigh t=200,width=300 ,left=300,top=2 00'
            > );
            >
            > 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.javas cript FAQ - http://jibbering.com/faq
            > [/color]

            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.docume nt). If spawnwin.docume nt 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
            _______________ _______________ ____

            Comment

            Working...