Formatting strings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas 'PointedEars' Lahn

    #16
    Re: Formatting strings - more complex!

    Nige wrote:[color=blue]
    > In comp.lang.javas cript, Thomas 'PointedEars' Lahn wrote:[color=green][color=darkred]
    >>> As I said in my other post (which I sent without giving full details,
    >>> sorry), I can't send the CGI data to the next page.[/color]
    >>Could you please explain why you assume this is the case?[/color]
    >
    > I've since discovered that I *can* send the date to the page, by
    > following the url with a ? then the server created date string.[/color]

    Yes, that is called a HTTP GET request which
    is also the default for submitting a form.
    [color=blue]
    > My only problem now is how to extract this from the document.locati on
    > property (it is there). I've tried code the parse the string to write
    > the last 8 digits, and code to find the "?" and write the remainder.[/color]

    That has nothing to do with CGI as you have told before!
    However, I have written a prototype that can be useful here:



    Note that the documentation is a bit out of date (see the source code in the
    ..js file.) `TValue' was changed to `Value', `TSearchStr' to `SearchString',
    and enhanced.js is now deprecated; use string.js instead. (Please also
    excuse that I wrote `class' in the comments in those days -- it'll be
    changed :-)).


    PointedEars

    Comment

    • Thomas 'PointedEars' Lahn

      #17
      Re: Formatting strings - more complex!

      Nige wrote:
      [color=blue]
      > Cracked it! My JS book (O'Reilly) implies that window.location returns a
      > string, but it doesn't![/color]

      (window.)locati on is in recent user agents a string value *and* an
      object with properties like `href', `protocol', `path', `hash' aso.

      Here, in Mozilla/5.0 rv:1.5 and IE 6.0 SP-1, it is. Which user-agent
      are you testing with?


      PointedEars

      Comment

      • Lasse Reichstein Nielsen

        #18
        Re: Formatting strings - more complex!

        Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:
        [color=blue]
        > (window.)locati on is in recent user agents a string value *and* an
        > object with properties like `href', `protocol', `path', `hash' aso.[/color]
        [color=blue]
        > Here, in Mozilla/5.0 rv:1.5 and IE 6.0 SP-1, it is. Which user-agent
        > are you testing with?[/color]

        In my IE6, it is only an object. It doesn't have the methods from
        String.prototyp e (e.g., charAt), and its typeof is "object".

        If you convert it to a string, either with String(location ),
        location.toStri ng() or ""+location , the resulting string contains
        the URL, but that just means that it can be converted to a string.

        There is some magic to the location object, though, since *assigning*
        to it will really assign to location.href.

        As a curiosity, in Opera 7 the location.valueO f method is the same
        as the location.toStri ng.

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Thomas 'PointedEars' Lahn

          #19
          Re: Formatting strings - more complex!

          Lasse Reichstein Nielsen wrote:
          [color=blue]
          > Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:[color=green]
          >> (window.)locati on is in recent user agents a string value *and* an
          >> object with properties like `href', `protocol', `path', `hash' aso.[/color]
          >[color=green]
          >> Here, in Mozilla/5.0 rv:1.5 and IE 6.0 SP-1, it is. Which user-agent
          >> are you testing with?[/color]
          >
          > In my IE6, it is only an object. It doesn't have the methods from
          > String.prototyp e (e.g., charAt), and its typeof is "object".[/color]

          You're right, the same goes for my UAs. What I meant was that
          it returns also a URI string (due to its toString() method) in
          the right context.

          In contrast, in older UAs like Opera 6 (IIRC), `location' stores
          only a primitive string value.
          [color=blue]
          > If you convert it to a string, either with String(location ),
          > location.toStri ng() or ""+location , the resulting string contains
          > the URL, but that just means that it can be converted to a string.[/color]

          ACK
          [color=blue]
          > There is some magic to the location object, though, since *assigning*
          > to it will really assign to location.href.[/color]

          There is no magic involved :) See


          [color=blue]
          > As a curiosity, in Opera 7 the location.valueO f method is the same
          > as the location.toStri ng.[/color]

          Same in Mozilla/5.0 and IE 6.0 SP-1, as expected.


          PointedEars

          Comment

          • Lasse Reichstein Nielsen

            #20
            Re: Formatting strings - more complex!

            Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:
            [color=blue]
            > In contrast, in older UAs like Opera 6 (IIRC), `location' stores
            > only a primitive string value.[/color]

            YRI (You Remember Incorrectly :)
            In Opera 4, 5 and 6, location is an object. I don't have Opera 3 installed,
            and Opera 2 doesn't support Javascript.

            The same goes for Netscape 4 and 3. You have to go back to Netscape 2
            to find a location property that is a plain string.
            [color=blue][color=green]
            > > There is some magic to the location object, though, since *assigning*
            > > to it will really assign to location.href.[/color]
            >
            > There is no magic involved :) See
            > http://devedge.netscape.com/library/.../location.html[/color]

            Tha qualified as "magic" to me (something that depends on internal
            code and cannot be implemented by a Javscript programmer, like the
            array length property [1]).

            It says:
            ---
            If you assign a string to the location property of an object,
            JavaScript creates a location object and assigns that string to its
            href property.
            ---
            That is not correct for *any* object. The following gives me "string":
            ---
            var x = {}; // or var x=document.body ;
            x.location = "foo";
            typeof x.location
            ---
            So, it is only for window objects, not any object.
            [color=blue][color=green]
            > > As a curiosity, in Opera 7 the location.valueO f method is the same
            > > as the location.toStri ng.[/color]
            >
            > Same in Mozilla/5.0 and IE 6.0 SP-1, as expected.[/color]

            In my IE 6, the location object doesn't have a valueOf property.
            What I mean is that in Opera is the *exact* same function, it doesn't
            just give the same result. That is:
            location.toStri ng == location.valueO f
            and
            location.valueO f.toString()
            gives
            ---
            function toString() {
            [native code]
            }
            ---

            /L
            [1] I know Netscape 4 and Mozilla have ways to make getters and setters
            for properties, but that is not portable Javascript.
            --
            Lasse Reichstein Nielsen - lrn@hotpop.com
            DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
            'Faith without judgement merely degrades the spirit divine.'

            Comment

            • Thomas 'PointedEars' Lahn

              #21
              Location object (was: Formatting strings - more complex!)

              Lasse Reichstein Nielsen wrote:
              [color=blue]
              > Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:[color=green]
              >> In contrast, in older UAs like Opera 6 (IIRC), `location' stores
              >> only a primitive string value.[/color]
              >
              > YRI (You Remember Incorrectly :)[/color]

              Having just installed Opera 6.0 again [1], I realize that you are both
              right *and* wrong! :-)

              I remembered correctly, *but* my testing method was in fact flawed:
              From the fact that Opera's `location' shows no properties when iterating
              through them with `for (var p in location)', I falsely concluded that it
              has none and is therefore no object at all.[2] But as you wrote, it is of
              type `object' and has at least `href', `search' and `protocol' properties
              (when I think about it, Opera won't have distributed this much if it had not.)

              Because you cannot rely on what iteration shows, is there a way to get
              all properties of an object other than brute force, and if that, how it
              is done?
              [color=blue]
              > In Opera 4, 5 and 6, location is an object.[/color]

              It is in v6, and most certainly is in v4 and v5.
              [color=blue]
              > I don't have Opera 3 installed,[/color]

              See [1].
              [color=blue]
              > The same goes for Netscape 4 and 3.[/color]

              ACK
              [color=blue][color=green][color=darkred]
              >> > There is some magic to the location object, though, since *assigning*
              >> > to it will really assign to location.href.[/color]
              >>
              >> There is no magic involved :) See
              >> http://devedge.netscape.com/library/.../location.html[/color]
              >
              > Tha qualified as "magic" to me (something that depends on internal
              > code and cannot be implemented by a Javscript programmer,[/color]

              OK. I don't consider things described in specifications "magic".
              [color=blue]
              > It says:
              > ---
              > If you assign a string to the location property of an object,
              > JavaScript creates a location object and assigns that string to its
              > href property.
              > ---
              > That is not correct for *any* object. The following gives me "string":
              > ---
              > var x = {}; // or var x=document.body ;
              > x.location = "foo";
              > typeof x.location
              > ---
              > So, it is only for window objects, not any object.[/color]

              It also says:

              | The location object is contained by the window object and is within its
              | scope. If you refer to a location object without specifying a window, the
              | location object represents the current location. If you refer to a
              | location object and specify a window name, as in windowReference .location,
              | the location object represents the location of the specified window.

              and BTW, your `x' is not a Location object.
              [color=blue][color=green][color=darkred]
              >> > As a curiosity, in Opera 7 the location.valueO f method is the same
              >> > as the location.toStri ng.[/color]
              >>
              >> Same in Mozilla/5.0 and IE 6.0 SP-1, as expected.[/color]
              >
              > In my IE 6, the location object doesn't have a valueOf property.[/color]

              Oops! Me too. Debug bug. System halted.


              PointedEars
              ___________
              [1] <http://arc.opera.com/pub/opera/>
              [2] <http://pointedears.de. vu/scripts/test/location.html>

              Comment

              • Lasse Reichstein Nielsen

                #22
                Re: Location object (was: Formatting strings - more complex!)

                Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:
                [color=blue]
                > Because you cannot rely on what iteration shows, is there a way to get
                > all properties of an object other than brute force, and if that, how it
                > is done?[/color]

                No. You can only get the enumerable properties. For the rest, you must
                do a brute force search (i.e., you can't in practice).

                In Opera, only methods are generally enumerable, and not even all of
                them. The enumerable properties of O7's location object are:
                assign, reload, replace, toString, and valueOf
                As you say, in O6, there are no enumerable properties.
                [color=blue][color=green]
                > > I don't have Opera 3 installed,[/color]
                >
                > See [1].[/color]

                I have it, it's just not installed right now :)
                [color=blue]
                > It also says:
                >
                > | The location object is contained by the window object and is within its
                > | scope. If you refer to a location object without specifying a window, the
                > | location object represents the current location. If you refer to a
                > | location object and specify a window name, as in windowReference .location,
                > | the location object represents the location of the specified window.[/color]

                That just sounds like normal scope rules when the "current" window object
                is also the global object of the execution context. Location objects are
                just properties of window objects.
                [color=blue]
                > and BTW, your `x' is not a Location object.[/color]

                Nope. But they did say that if you assigned to the location property
                of an object, it would create a location object in its place. Apparenty
                it is only true for window objects.

                /L
                --
                Lasse Reichstein Nielsen - lrn@hotpop.com
                DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                'Faith without judgement merely degrades the spirit divine.'

                Comment

                • Dr John Stockton

                  #23
                  Re: Formatting strings - more complex!

                  JRS: In article <20031106163514 .12300.00001486 @mb-m20.aol.com>, seen in
                  news:comp.lang. javascript, HikksNotAtHome <hikksnotathome @aol.com>
                  posted at Thu, 6 Nov 2003 21:35:14 :-
                  [color=blue]
                  >I have no problem with it. I dont recieve the mails (If I do, they get
                  >deleted), so I fail to see how Usenet is a "private" place. As I said, don't
                  >try to email someone, no problems. Trying to get outside of the public Usenet
                  >into private Email is crossing a boundary that I don't care to cross. It opens
                  >up too many problems. If the "Netiquette " says its ok, I don't care, I don't do
                  >it and I won't do it.[/color]


                  It is possible that AOL may have problems with it; certainly they
                  should. If Mr. H Ikksnot gets a couple of AOL accounts, one for use at
                  work and the other at home, he may be disgruntled to receive your spam.

                  One should not use an address that may cause mail to be directed to an
                  account, extant or otherwise, that one does not have positive permission
                  to use.

                  Different providers, however, do actually state different, or no,
                  conditions; presumably depending on a combination of their corporate
                  intelligence and public-spiritedness.

                  It is possible that AOL may have created, or be willing to create, some
                  range or ranges of left parts that will not be allowed for customers and
                  can therefore be offered for your purpose; they would then probably
                  arrange to bounce or dump all messages to that range efficiently.

                  --
                  © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME ©
                  Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
                  Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm> : about usage of News.
                  No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

                  Comment

                  • Nige

                    #24
                    Re: Formatting strings - more complex!

                    In comp.lang.javas cript, Thomas 'PointedEars' Lahn wrote:
                    [color=blue][color=green]
                    >> My only problem now is how to extract this from the document.locati on
                    >> property (it is there). I've tried code the parse the string to write
                    >> the last 8 digits, and code to find the "?" and write the remainder.[/color]
                    >
                    >That has nothing to do with CGI as you have told before![/color]

                    No, indeed, it was my flawed understanding of the object returned from
                    the .location property. All sorted now.

                    Next year I'm going to be teaching a university course that involves JS,
                    all I have to do is stay one step ahead of the students ;-)


                    --
                    Nige

                    Please replace YYYY with the current year
                    ille quis mortem cum maximus ludos, vincat

                    Comment

                    • Richard Cornford

                      #25
                      Re: Location object (was: Formatting strings - more complex!)

                      "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
                      news:65hw2g6i.f sf@hotpop.com.. .[color=blue][color=green]
                      >>Because you cannot rely on what iteration shows, is there a
                      >>way to get all properties of an object other than brute force,
                      >>and if that, how it is done?[/color]
                      >
                      >No. You can only get the enumerable properties. For the rest,
                      >you must do a brute force search (i.e., you can't in practice).[/color]
                      <snip>

                      Do you really mean you can't in practice? Certainly it would not be
                      practical to test every combination of character sequence that could be
                      a property name (the end on the universe would arrive before the
                      results), but I don't see a problem with trying each item in a list of
                      likely property names against an object to see which return
                      non-undefined values. Then the usefulness of the results only depends on
                      the quality of the list of likely property names. It wouldn't be quick
                      but it wouldn't be so slow as to be impractical.

                      Richard.


                      Comment

                      • Lasse Reichstein Nielsen

                        #26
                        Re: Location object (was: Formatting strings - more complex!)

                        "Richard Cornford" <Richard@litote s.demon.co.uk> writes:
                        [color=blue]
                        > Do you really mean you can't in practice? Certainly it would not be
                        > practical to test every combination of character sequence that could
                        > be a property name (the end on the universe would arrive before the
                        > results),[/color]

                        Find them all, no. It is indeed the heat death of the Universe that
                        prevents that.
                        [color=blue]
                        > but I don't see a problem with trying each item in a list of likely
                        > property names against an object to see which return non-undefined
                        > values.[/color]

                        Absolutely possible. Later versions of Javascript even has a way
                        to check whether an object has a property ("foo" in obj).
                        [color=blue]
                        > Then the usefulness of the results only depends on the
                        > quality of the list of likely property names. It wouldn't be quick
                        > but it wouldn't be so slow as to be impractical.[/color]

                        If you know what to look for, it is easier to find it :)

                        /L
                        --
                        Lasse Reichstein Nielsen - lrn@hotpop.com
                        DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                        'Faith without judgement merely degrades the spirit divine.'

                        Comment

                        • Dr John Stockton

                          #27
                          Re: Formatting strings - more complex!

                          JRS: In article <dtrmqv493s8j8l fdh52f4nmsk4vb7 b6cm6@4ax.com>, seen in
                          news:comp.lang. javascript, Nige <uYYYY@ntlworld .com> posted at Fri, 7
                          Nov 2003 10:47:29 :-
                          [color=blue]
                          >In comp.lang.javas cript, Thomas 'PointedEars' Lahn wrote:
                          >[color=green][color=darkred]
                          >>> Time zones don't enter into it, all users are in the UK.[/color]
                          >>I wonder how you can be sure.[/color]
                          >
                          >Because it is a campaign site for broadband in Kent.[/color]

                          I am reliably informed that there is a modicum of Kent that keeps Paris
                          Time. However, they are probably not possible direct customers for the
                          broadband service. And if they were, they might be customers best
                          avoided (on mere pragmatic grounds; nothing uncomplimentary ).

                          --
                          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                          Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
                          PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
                          Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

                          Comment

                          Working...