test for ie or netscape

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

    test for ie or netscape

    I have seen some codes that can test for the browser and give values
    accordingly. I tried to read the FAQ, but was unable to find a simple
    version of this. What I want is

    If Netscape-test {
    code for netscape users
    }

    If IE-test {
    code for ie users
    }



  • Michael Winter

    #2
    Re: test for ie or netscape

    On Tue, 3 Feb 2004 14:12:12 -0600, Treetop <treetop@netfro nt.net> wrote:
    [color=blue]
    > I have seen some codes that can test for the browser and give values
    > accordingly. I tried to read the FAQ, but was unable to find a simple
    > version of this.[/color]

    Why do you want to do this? If you are trying to determine what code *can*
    be executed, use feature detection, not browser detection. For example, to
    see if document.getEle mentById() is supported use

    if( document.getEle mentById ) {
    }

    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    • Treetop

      #3
      Re: test for ie or netscape

      I have created a script to send data, text and an image src, to an
      iframe. I have code that works for IE, and I have code that works for
      Netscape, but I can't find code that works for both. I want the
      following

      if test-for-netscape {
      window.frames['external'].setup(links[aNum]);
      }
      else {
      document.extern al.setup(links[aNum]);
      }


      "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
      news:opr2s842fu 5vklcq@news-text.blueyonder .co.uk...[color=blue]
      > On Tue, 3 Feb 2004 14:12:12 -0600, Treetop <treetop@netfro nt.net>[/color]
      wrote:[color=blue]
      >[color=green]
      > > I have seen some codes that can test for the browser and give[/color][/color]
      values[color=blue][color=green]
      > > accordingly. I tried to read the FAQ, but was unable to find a[/color][/color]
      simple[color=blue][color=green]
      > > version of this.[/color]
      >
      > Why do you want to do this? If you are trying to determine what code[/color]
      *can*[color=blue]
      > be executed, use feature detection, not browser detection. For[/color]
      example, to[color=blue]
      > see if document.getEle mentById() is supported use
      >
      > if( document.getEle mentById ) {
      > }
      >
      > Mike
      >
      > --
      > Michael Winter
      > M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to[/color]
      reply)


      Comment

      • kaeli

        #4
        Re: test for ie or netscape

        In article <bvov8r$vc8r8$1 @ID-221536.news.uni-berlin.de>,
        treetop@netfron t.net enlightened us with...[color=blue]
        > I have seen some codes that can test for the browser and give values
        > accordingly. I tried to read the FAQ, but was unable to find a simple
        > version of this. What I want is
        >[/color]

        And if I use Opera? Or Safari? Or Konqueror? Mac users tend to like
        Safari. What about Mozilla? Linux users tend to like Mozilla.
        What about if I use Netscape 4? It isn't anything close to Netscape 6 in
        regards to what it can do.
        How about if I use IE3? It doesn't support half the stuff IE5 does.

        Don't test for browsers. You'll end up coming back here wondering why
        your code doesn't work in Netscape 8 when it comes out or something.
        Test for the objects you want to use.
        if (document.layer s)
        // do something with that for NN4
        else if (document.all && ! document.getEle mentById)
        // do something with old IE
        else if (document.getEl ementById)
        // recent browsers like IE5+, NN6+, Mozilla, Opera...


        --
        --
        ~kaeli~
        Those who jump off a bridge in Paris... are in Seine.



        Comment

        • Treetop

          #5
          Re: test for ie or netscape


          "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
          news:MPG.1a89c8 397a15dda5989bb 1@nntp.lucent.c om...[color=blue]
          > In article <bvov8r$vc8r8$1 @ID-221536.news.uni-berlin.de>,
          > treetop@netfron t.net enlightened us with...[color=green]
          > > I have seen some codes that can test for the browser and give[/color][/color]
          values[color=blue][color=green]
          > > accordingly. I tried to read the FAQ, but was unable to find a[/color][/color]
          simple[color=blue][color=green]
          > > version of this. What I want is
          > >[/color]
          >
          > And if I use Opera? Or Safari? Or Konqueror? Mac users tend to like
          > Safari. What about Mozilla? Linux users tend to like Mozilla.
          > What about if I use Netscape 4? It isn't anything close to Netscape[/color]
          6 in[color=blue]
          > regards to what it can do.
          > How about if I use IE3? It doesn't support half the stuff IE5 does.
          >
          > Don't test for browsers. You'll end up coming back here wondering[/color]
          why[color=blue]
          > your code doesn't work in Netscape 8 when it comes out or something.
          > Test for the objects you want to use.
          > if (document.layer s)
          > // do something with that for NN4
          > else if (document.all && ! document.getEle mentById)
          > // do something with old IE
          > else if (document.getEl ementById)
          > // recent browsers like IE5+, NN6+, Mozilla, Opera...[/color]

          I need to have a way to test for IE5+ versus NN6+.


          For my code to work for NN6 I need the following:

          window.frames['external'].setup(links[aNum]);


          For IE6 I need the following:

          document.extern al.setup(links[aNum]);



          Comment

          • kaeli

            #6
            Re: test for ie or netscape

            In article <bvp2s3$uvfit$1 @ID-221536.news.uni-berlin.de>,
            treetop@netfron t.net enlightened us with...
            [color=blue]
            >
            > I need to have a way to test for IE5+ versus NN6+.[/color]

            I bet you don't.
            [color=blue]
            >
            >
            > For my code to work for NN6 I need the following:
            >
            > window.frames['external'].setup(links[aNum]);
            >
            >
            > For IE6 I need the following:
            >
            > document.extern al.setup(links[aNum]);
            >[/color]

            That makes no sense to me without a context.

            Are you trying to call a function resident (defined) in another frame of
            a frameset?
            If so, the following is mine (well, it's HVMenu's really) and it works
            on both IE5+ and NN6+.
            It is called from the "main" frame of a 3 frame (top, left, main)
            layout. It calls a function defined in the 'left' frame from the 'main'
            frame.

            if(parent.frame s[0]&&parent.fra mes['leftFrame'].Go)
            {
            parent.frames['leftFrame'].Go();
            }

            If that's the kind of thing you're trying, tell me more about your frame
            layout and what frame is calling what function and what frame name that
            function is in.

            --
            --
            ~kaeli~
            A backward poet writes... inverse.



            Comment

            • Michael Winter

              #7
              Re: test for ie or netscape

              On Tue, 03 Feb 2004 20:39:38 GMT, Treetop <treetop@netfro nt.net> wrote:
              [color=blue]
              > I have created a script to send data, text and an image src, to an
              > iframe. I have code that works for IE, and I have code that works for
              > Netscape, but I can't find code that works for both. I want the
              > following
              >
              > if test-for-netscape {
              > window.frames['external'].setup(links[aNum]);
              > }
              > else {
              > document.extern al.setup(links[aNum]);
              > }[/color]

              I don't know if this will work, but give it a shot:

              var ifExternal = null;

              if( window.frames['external'] ) {
              ifExternal = window.frames['external'];
              } else if( document.extern al ) {
              ifExternal = window.external ;
              }

              if( ifExternal ) {
              ifExternal.setu p( links[ aNum ]);
              }

              The need for the two different code paths seems to be because IE (and
              Opera) don't include IFRAMEs in the frames collection, though they do
              support the frames collection in general (or seem to).

              Mike

              --
              Michael Winter
              M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

              Comment

              • Dennis M. Marks

                #8
                Re: test for ie or netscape

                I have read the following message from "Treetop" <treetop@netfro nt.net>
                and have decided to lend my vast knowledge.

                The writer said:[color=blue]
                > I have seen some codes that can test for the browser and give values
                > accordingly. I tried to read the FAQ, but was unable to find a simple
                > version of this. What I want is
                >
                > If Netscape-test {
                > code for netscape users
                > }
                >
                > If IE-test {
                > code for ie users
                > }
                >
                >
                >
                >[/color]

                and my reply is:
                Do a Google search on "browser sniffer"

                --
                Dennis M. Marks

                Replace domain.invalid with dcsi.net


                -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
                http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
                -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

                Comment

                • Treetop

                  #9
                  Re: test for ie or netscape

                  OK he it goes...... Some of my clients are local contractors /
                  construction companies. They like to have images to show off current
                  and past projects. Most of the time it involves an image and some
                  text to explain what picture is. The last update I did was over 70
                  images. I decided to have a blank page that could be updated with a
                  link, that would put the source for the image and text for the image
                  on that page, to save me time creating 70 pages. I was unable to find
                  a way and had to create 70 pages. Not fun.

                  Today I finally put enough information together from different sources
                  to create the following code in two pages. I don't like they way I
                  trick the system into using the correct code. I also don't have a way
                  to test other browsers other than IE and Netscape. This code works on
                  my sytem in both IE 6 and Netscape 7.02.



                  Netscape uses this code:
                  window.frames['external'].setup(links[aNum]);}

                  IE uses this code:
                  document.extern al.setup(links[aNum]);





                  index page:

                  <table border="1" width="600">
                  <tr valign="top">
                  <td width="200">

                  <script language="javas cript" type="text/javascript">

                  var links=new Array();
                  links[4]=new Array("pic1.jpg ","pic1 link text","text for pic1");
                  links[3]=new Array("pic2.jpg ","pic2 link text","text for pic2");
                  links[2]=new Array("pic3.jpg ","pic3 link text","text for pic3");
                  links[1]=new Array("pic4.jpg ","pic4 link text","text for pic4");

                  function showImg(aNum)
                  {
                  if (navigator.appN ame.substring(0 , 7) != "Microso"){
                  window.frames['external'].setup(links[aNum]);}
                  else {
                  document.extern al.setup(links[aNum]);
                  }
                  };


                  for (var i=links.length-1;i>=0;i--)
                  {
                  document.write( '<a href="#" onclick=showImg ("'+i+'")>' + links[i][1] +
                  '</a><br>');
                  }

                  </script>

                  </td>
                  <td align="center" width="500">
                  <iframe name="external" id="external" style="width:10 0%;height:500px "
                  src="picture.ht ml"></iframe>
                  </td></tr></table>




                  here is the code in the pictrure.html file

                  <script language="javas cript">
                  function setup(aLink)
                  {
                  document.getEle mentById("pic") .src=aLink[0];
                  document.getEle mentById("title ").innerHTML=aL ink[2];
                  }
                  </script>
                  </head>
                  <body>

                  <center>
                  <img src="pic1.jpg" id="pic">
                  <p id="title">Tex t for Pic1</p>
                  </center>





                  Comment

                  • Treetop

                    #10
                    Re: test for ie or netscape

                    OK he it goes...... Some of my clients are local contractors /
                    construction companies. They like to have images to show off current
                    and past projects. Most of the time it involves an image and some
                    text to explain what picture is. The last update I did was over 70
                    images. I decided to have a blank page that could be updated with a
                    link, that would put the source for the image and text for the image
                    on that page, to save me time creating 70 pages. I was unable to find
                    a way and had to create 70 pages. Not fun.

                    Today I finally put enough information together from different sources
                    to create the following code in two pages. I don't like they way I
                    trick the system into using the correct code. I also don't have a way
                    to test other browsers other than IE and Netscape. This code works on
                    my sytem in both IE 6 and Netscape 7.02.



                    Netscape uses this code:
                    window.frames['external'].setup(links[aNum]);}

                    IE uses this code:
                    document.extern al.setup(links[aNum]);





                    index page:

                    <table border="1" width="600">
                    <tr valign="top">
                    <td width="200">

                    <script language="javas cript" type="text/javascript">

                    var links=new Array();
                    links[4]=new Array("pic1.jpg ","pic1 link text","text for pic1");
                    links[3]=new Array("pic2.jpg ","pic2 link text","text for pic2");
                    links[2]=new Array("pic3.jpg ","pic3 link text","text for pic3");
                    links[1]=new Array("pic4.jpg ","pic4 link text","text for pic4");

                    function showImg(aNum)
                    {
                    if (navigator.appN ame.substring(0 , 7) != "Microso"){
                    window.frames['external'].setup(links[aNum]);}
                    else {
                    document.extern al.setup(links[aNum]);
                    }
                    };


                    for (var i=links.length-1;i>=0;i--)
                    {
                    document.write( '<a href="#" onclick=showImg ("'+i+'")>' + links[i][1] +
                    '</a><br>');
                    }

                    </script>

                    </td>
                    <td align="center" width="500">
                    <iframe name="external" id="external" style="width:10 0%;height:500px "
                    src="picture.ht ml"></iframe>
                    </td></tr></table>




                    here is the code in the pictrure.html file

                    <script language="javas cript">
                    function setup(aLink)
                    {
                    document.getEle mentById("pic") .src=aLink[0];
                    document.getEle mentById("title ").innerHTML=aL ink[2];
                    }
                    </script>
                    </head>
                    <body>

                    <center>
                    <img src="pic1.jpg" id="pic">
                    <p id="title">Tex t for Pic1</p>
                    </center>


                    Comment

                    • Bas Cost Budde

                      #11
                      Re: test for ie or netscape

                      Dennis M. Marks wrote:
                      [color=blue][color=green]
                      >>I have seen some codes that can test for the browser and give values
                      >>accordingly . I tried to read the FAQ, but was unable to find a simple
                      >>version of this. What I want is[/color]
                      >
                      > and my reply is:
                      > Do a Google search on "browser sniffer"[/color]

                      Maybe; but the discussion as I perceive it tends towards object
                      detection, not browser sniffing.

                      Er, I don't want to start a war here, if this is still opiniated matter,
                      I'm out.
                      --
                      Bas Cost Budde


                      Comment

                      • Bas Cost Budde

                        #12
                        Re: test for ie or netscape

                        >>I need to have a way to test for IE5+ versus NN6+.[color=blue]
                        >
                        > I bet you don't.[/color]

                        Maybe this should/could read: I know a way for IE5, and I know a
                        (different) way for NN6, and I'm looking for any reliable way to
                        distinguish between the two possibilities.

                        I, personally, wouldn't want to drop in the gap when both tests for IE5
                        and NN6 fail. That convinced me to use object detection, not browser
                        sniffing.

                        --
                        Bas Cost Budde


                        Comment

                        • Richard Cornford

                          #13
                          Re: test for ie or netscape

                          "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
                          news:opr2tc5408 5vklcq@news-text.blueyonder .co.uk...
                          <snip>[color=blue]
                          >The need for the two different code paths seems to be because
                          >IE (and Opera) don't include IFRAMEs in the frames collection,
                          >though they do support the frames collection in general
                          >(or seem to).[/color]

                          IE and Opera do make IFRAMEs members of the frames collection. By
                          integer index and NAME attribute, ID attributes are more problematic and
                          for cross-browser scripting NAME attributes are preferred, though they
                          may be doubled up with corresponding ID attributes if needed.

                          Richard.


                          Comment

                          • Treetop

                            #14
                            Re: test for ie or netscape


                            "Richard Cornford" <Richard@litote s.demon.co.uk> wrote in message
                            news:bvp8m1$5n6 $1$8300dec7@new s.demon.co.uk.. .[color=blue]
                            > "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
                            > news:opr2tc5408 5vklcq@news-text.blueyonder .co.uk...
                            > <snip>[color=green]
                            > >The need for the two different code paths seems to be because
                            > >IE (and Opera) don't include IFRAMEs in the frames collection,
                            > >though they do support the frames collection in general
                            > >(or seem to).[/color]
                            >
                            > IE and Opera do make IFRAMEs members of the frames collection. By
                            > integer index and NAME attribute, ID attributes are more problematic[/color]
                            and[color=blue]
                            > for cross-browser scripting NAME attributes are preferred, though[/color]
                            they[color=blue]
                            > may be doubled up with corresponding ID attributes if needed.
                            >
                            > Richard.
                            >[/color]

                            What do you recommend I use then to make this work? If you have an
                            example of code would be wonderful.


                            Comment

                            • Treetop

                              #15
                              Re: test for ie or netscape


                              "Bas Cost Budde" <bas@heuveltop. org> wrote in message
                              news:bvp471$rpm $1@news2.solcon .nl...[color=blue][color=green][color=darkred]
                              > >>I need to have a way to test for IE5+ versus NN6+.[/color]
                              > >
                              > > I bet you don't.[/color]
                              >
                              > Maybe this should/could read: I know a way for IE5, and I know a
                              > (different) way for NN6, and I'm looking for any reliable way to
                              > distinguish between the two possibilities.
                              >
                              > I, personally, wouldn't want to drop in the gap when both tests for[/color]
                              IE5[color=blue]
                              > and NN6 fail. That convinced me to use object detection, not browser
                              > sniffing.
                              >[/color]

                              What do you recommend I use then to make this work? If you have an
                              example of code would be wonderful.


                              Comment

                              Working...