To test a function with a Broser

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

    To test a function with a Broser

    Hi at all,
    I am looking for a mean to test if a function work with a certain Browser or
    not.
    I'ld like to make a funcrion that return true if the browse is compatible
    with a certain funcrion or style and false if not.
    Have you any idea?
    Thank in advance an dbest regards.
    Pietro.


  • Lasse Reichstein Nielsen

    #2
    Re: To test a function with a Broser

    "Pietro" <pietroNOSPAM@e urotime.it> writes:
    [color=blue]
    > I am looking for a mean to test if a function work with a certain Browser or
    > not.[/color]

    Testing whether it works is harder than just testing whether it exists.
    Existence is easy. E.g., to test for document.getEle mentById, you can
    just do:

    function existsDGEBI() {
    return typeof document.getEle mentById == "function";
    }
    [color=blue]
    > I'ld like to make a funcrion that return true if the browse is compatible
    > with a certain funcrion or style and false if not.[/color]

    It might be easier to help, if you were a little bit more specific.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Pietro

      #3
      Re: To test a function with a Broser

      Hi Lasse,
      the function that I'ld want to test is:
      document.getEle mentById("objec t")
      Is it possible to test therefore to know in advance if this function work in
      any browser that the user can have?
      Thanks
      Pietro

      "Lasse Reichstein Nielsen" <lrn@hotpop.com > ha scritto nel messaggio
      news:7k4sft03.f sf@hotpop.com.. .[color=blue]
      > "Pietro" <pietroNOSPAM@e urotime.it> writes:
      >[color=green]
      > > I am looking for a mean to test if a function work with a certain[/color][/color]
      Browser or[color=blue][color=green]
      > > not.[/color]
      >
      > Testing whether it works is harder than just testing whether it exists.
      > Existence is easy. E.g., to test for document.getEle mentById, you can
      > just do:
      >
      > function existsDGEBI() {
      > return typeof document.getEle mentById == "function";
      > }
      >[color=green]
      > > I'ld like to make a funcrion that return true if the browse is[/color][/color]
      compatible[color=blue][color=green]
      > > with a certain funcrion or style and false if not.[/color]
      >
      > It might be easier to help, if you were a little bit more specific.
      >
      > /L
      > --
      > Lasse Reichstein Nielsen - lrn@hotpop.com
      > Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
      > 'Faith without judgement merely degrades the spirit divine.'[/color]


      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: To test a function with a Broser

        "Pietro" <pietroNOSPAM@e urotime.it> writes:
        [color=blue]
        > the function that I'ld want to test is:
        > document.getEle mentById("objec t")[/color]

        The function is "document.getEl ementById". Calling it gives a DOM
        node, if there is one with that id.

        I think it is safe to assume, that if the function exists, then it
        also works correctly. That is, you can just do
        if (document.getEl ementById) {
        ... it exists, do whatever you want with it...

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • HikksNotAtHome

          #5
          Re: To test a function with a Broser

          In article <smngdzk1.fsf@h otpop.com>, Lasse Reichstein Nielsen <lrn@hotpop.com >
          writes:
          [color=blue]
          >I think it is safe to assume, that if the function exists, then it
          >also works correctly. That is, you can just do
          > if (document.getEl ementById) {
          > ... it exists, do whatever you want with it...
          >[/color]

          The existence of document.getEle mentById doesn't imply you can "do whatever you
          want with it". It only implies that the browser supports getElementById, any
          further uses of it you still need to test for. Not the use of getElementById,
          but the methods of it need to be tested as well.
          --
          Randy

          Comment

          • Lasse Reichstein Nielsen

            #6
            Re: To test a function with a Broser

            hikksnotathome@ aol.com (HikksNotAtHome ) writes:
            [color=blue]
            > The existence of document.getEle mentById doesn't imply you can "do
            > whatever you want with it". It only implies that the browser
            > supports getElementById, any further uses of it you still need to
            > test for.[/color]

            If we want to take that line of thought to the limit, all it shows is
            that the value of the property "document" of the global object is
            itself an object (or is convertible to one), and that it has a
            property called "getElementById " that has a value that is not
            convertible to "false".

            We might also need to check that "document" really refers to a
            document, that getElementById is a function, and that it takes an
            argument and returns a DOM node that has that argument as an ID
            attribute.

            We should also test that we are really running a version of
            Javascript, and that the Javascript interpreter works correctly for
            all the language constructs that we use.

            This is ofcourse ridiculous. We have to draw a line somewhere, and
            assume that everything below that line works to our assumtions.

            What I say is that, in my opinion, which I prefer to think of as
            informed, the line can be drawn at the existence of a "getElementById "
            propertyin the "document" object (which is assumed to exist). If
            "getElementById " exists, then I will use it and assume that it is
            indeed an implementation of the method specified in the DOM 2 Core W3C
            recommendation.

            I haven't yet seen a browser where that assumption fails, and I don't
            expect to see on.
            [color=blue]
            > Not the use of getElementById, but the methods of it need to be
            > tested as well.[/color]

            What is the "use" and "methods" of "getElementById "?

            /L
            --
            Lasse Reichstein Nielsen - lrn@hotpop.com
            Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
            'Faith without judgement merely degrades the spirit divine.'

            Comment

            • HikksNotAtHome

              #7
              Re: To test a function with a Broser

              In article <oey4dmqj.fsf@h otpop.com>, Lasse Reichstein Nielsen <lrn@hotpop.com >
              writes:
              [color=blue]
              >hikksnotathome @aol.com (HikksNotAtHome ) writes:
              >[color=green]
              >> The existence of document.getEle mentById doesn't imply you can "do
              >> whatever you want with it". It only implies that the browser
              >> supports getElementById, any further uses of it you still need to
              >> test for.[/color][/color]

              <--snip-->
              [color=blue]
              >We should also test that we are really running a version of
              >Javascript, and that the Javascript interpreter works correctly for
              >all the language constructs that we use.[/color]

              <sarcasm>
              We should also test for the existence of the if statement, and that it is
              indeed an interpreter.
              <sarcasm />
              [color=blue]
              >This is of course ridiculous. We have to draw a line somewhere, and
              >assume that everything below that line works to our assumtions.[/color]

              Absolutely.
              [color=blue]
              >What I say is that, in my opinion, which I prefer to think of as
              >informed, the line can be drawn at the existence of a "getElementById "
              >propertyin the "document" object (which is assumed to exist). If
              >"getElementByI d" exists, then I will use it and assume that it is
              >indeed an implementation of the method specified in the DOM 2 Core W3C
              >recommendation .[/color]

              if (document.getEl ementById){
              //use it for anything you want to.
              //ok, lets use it:
              document.getEle mentById('myScr iptTagId').src = someOtherJSFile .js;
              }

              That above is the context that I read your statement in, and in that context,
              its not true. Can you assume that you can use getElementById in following
              constructs? Sure. Can you just "use it to do whatever you want with it" ? No.
              Or perhaps I am just "uninformed "?

              --
              Randy

              Comment

              • Jim Ley

                #8
                Re: To test a function with a Broser

                On 02 Sep 2003 04:53:35 +0200, Lasse Reichstein Nielsen
                <lrn@hotpop.com > wrote:
                [color=blue]
                >Further use of elements must either be assumed to work or be checked
                >first, depending on what feature it is (e.g., changing the src
                >property of an image can be assumed to work, while changing the
                >src property of a script element can not be assumed to do anything).[/color]

                I don't agree with this, I believe you should always check that what
                you get back from gEBI is a node and null before you try doing
                anything else, there are content modifying proxies, and there are
                broken connections.

                Jim.
                --
                comp.lang.javas cript FAQ - http://jibbering.com/faq/

                Comment

                Working...