SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Enthusiast Incubator's Avatar
    Join Date
    Apr 2002
    Location
    Good old Belgium
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript if statement

    Well, i need an if statement to check what browser he is using.
    If he is using ie4 or 5, then use nav1, else use nav two, but how do I check on the IE?

    but more importantly, how do I make him do the following:
    Code:
    browser = (((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 3 )) || ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 )))
    
    if (browser){
      (then open nav1.htm)--> in the same frame as this page (in javascript code please)
       }
    else {
     (open nav2.htm)-->in the same frame as this page (in javascript code please)
    
    }
    so, err, I am a little stuck here
    (i know I already ansewered the first part of my question)
    Last edited by Incubator; Apr 10, 2002 at 05:08.
    "Press any key to continue. Press any other key to exit."

  2. #2
    Posts rarely lloydi's Avatar
    Join Date
    Jan 2002
    Location
    Swindon UK
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    browser = // etc etc

    if (browser){
    (self.location.href="nav1.htm";}
    else {
    (self.location.href="nav2.htm";}
    }
    Build Your Own Web Site the Right Way!
    A beginners' HTML/CSS book with web standards at its heart
    The Ultimate HTML Reference
    A complete reference, in glorious hardback

  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    w3school

    have a look at there example

  4. #4
    SitePoint Enthusiast Incubator's Avatar
    Join Date
    Apr 2002
    Location
    Good old Belgium
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks
    but i got another problem, i made it to check on ie6, and i have it (of course) but, my statement is, when you have ie6, show nav1. else nav 2
    the code you gave me works, but for some reason it acts like I have no ie6.
    it always shows nav2 instead of nav1 with me.

    edit: when I enter the following code:
    Code:
    <script language="JavaScript">
    <!--
    
    if (parseInt(navigator.appVersion) >= 6 ){
    	self.location.href="nav1";} 
    else {
    	self.location.href="nav2";}
    -->
    </script>
    I expect that eveyone with ie6 and higher (for the future) will see nav1 and everyone else nav2.
    Well guess what, it is the other way around. I had to change >= 6 in <= 6.
    But iīm not sure if it will be correct on ie5 users.
    any help here is much appreciated!
    Last edited by Incubator; Apr 10, 2002 at 09:34.
    "Press any key to continue. Press any other key to exit."

  5. #5
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why dont you

    PHP Code:

    var ns4= (navigator.appName=="Netscape"&&navigator.appVersion>=4) var ns4= (navigator.appName=="Microsoft Internet Explorer"&&navigator.appVersion>=4
    are you using code that requires functionality of ns 6 then just change the number.

  6. #6
    SitePoint Guru moonman's Avatar
    Join Date
    Dec 2000
    Location
    The Sea of Tranquility
    Posts
    696
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's a product called Browserhawk which you can use to detect browsers, some plugins, language etc.

  7. #7
    SitePoint Enthusiast Incubator's Avatar
    Join Date
    Apr 2002
    Location
    Good old Belgium
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    moonman, err, that thing is way beyond my understanding

    anywhay, I tried something out.
    To any IE5 users who read this, go to http://www.flandersmilk.com/dev/Frans/frans.htm
    and if you see a nav bar that works, all is fine.

    for ie6 users, you should see a nav bar with shadow, opacy, ...

    and please say if it works or not + ie version
    thnx
    Last edited by Incubator; Apr 11, 2002 at 02:41.
    "Press any key to continue. Press any other key to exit."

  8. #8
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Moved to a more appropriate forum

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  9. #9
    SitePoint Guru moonman's Avatar
    Join Date
    Dec 2000
    Location
    The Sea of Tranquility
    Posts
    696
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Incubator
    moonman, err, that thing is way beyond my understanding
    Sorry then. It's a bit beyond me as well, but my boss loves it.

  10. #10
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you have anything specifically that NEEDS version 6 and up. Ie 5.5 supports most of the things the average javascript programmer uses. Try detecting via the dom...

    if (document.all) //ie 5 - 5.5
    {

    }
    else if (document.getElementById) /ie 6.0 AND ns6.0
    {

    }
    else // every other browser that doesn't support those
    {

    }

    Your code may work fine in IE 5 if you try it out (you may be surprised) and then all you have to is

    if (document.all || document.getElementById)
    {

    }
    else
    {

    }

    You can also combine these with the tradition detection techniques above for even more accuracy.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  11. #11
    SitePoint Enthusiast Incubator's Avatar
    Join Date
    Apr 2002
    Location
    Good old Belgium
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, the viewers either have ie5 or ie6, noting in between.(africans)
    the nav bar works only properly in ie6, so I had to remove the effects so it would work in ie5 too.
    But I did many changes andtrials, but it always chooses nav1.
    nav1 is for ie6 and nav2 is for ie5
    it is like he totally ignores my if statement.
    he is supposed to check wether it is lower then ie6, then show nav2, else nav1.
    I tried reversing it, and using the ! statement, but to no avail

    and Mealstrom, are you sure comment lines behind the if statement will do the trick? (sorry but i donīt know much about JavaScript)
    "Press any key to continue. Press any other key to exit."

  12. #12
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The comments are simply there for you. I pmed you with another answer. It should work and will show nav2.htm to anyone using ie5.5 and less and netscape 4.x and show nav1.htm to ie6 and netscape 6.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  13. #13
    SitePoint Enthusiast Incubator's Avatar
    Join Date
    Apr 2002
    Location
    Good old Belgium
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, believe it or not, but it does the opposite :'(
    i have ie6, and now i get to see nav2 instead of nav1.
    i really donīt undersyand how this is possible
    "Press any key to continue. Press any other key to exit."

  14. #14
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    <HTML>
    <
    HEAD><TITLE>Detecting the browser type</TITLE></HEAD>
    <
    BODY>
    <
    H3>Details of your browser</H3>
    <
    TABLE>
     <
    TR>
      <
    TD ALIGN="RIGHT">navigator.userAgent:</TD>
      <
    TD><B>
      <
    SCRIPT LANGUAGE="JavaScript">
      <!--
        
    document.write(navigator.userAgent)
      
    //-->
      
    </SCRIPT></B>
      </TD>
     </TR>
     <TR>
      <TD ALIGN="RIGHT">navigator.appName:</TD>
      <TD><B>
      <SCRIPT LANGUAGE="JavaScript">
      <!--
        document.write(navigator.appName)
      //-->
      </SCRIPT></B>
      </TD>
     </TR>
     <TR>
      <TD ALIGN="RIGHT">navigator.appVersion:</TD>
      <TD><B>
      <SCRIPT LANGUAGE="JavaScript">
      <!--
        document.write(navigator.appVersion)
      //-->
      </SCRIPT></B>
      </TD>
     </TR>
    </TABLE><P>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
      if (navigator.appName.indexOf('Netscape') != -1) {
        document.write('To upgrade your browser go to ' +
          '<A  HREF = "http://home.netscape.com/download/">' +
          'http://home.netscape.com/download/<\/A><\/P>');
        if (navigator.appVersion.substr(0, 1) > 3)
          document.write('You can use Netscape Dynamic HTML');
      }
      if (navigator.appName.indexOf('Microsoft') != -1) {
        document.write('To upgrade your browser go to ' +
          '<A  HREF = "http://www.microsoft.com/ie/">' + 
          'http://www.microsoft.com/ie/<\/A><\/P>');
        if (navigator.appVersion.substr(0, 1) > 3)
          document.write('You can use Microsoft Dynamic HTML');
      }
    //-->
    </SCRIPT>
    <NOSCRIPT>
      Sorry, your browser doesn't support client-side scripting, 
      so it can't display the details about your browser.
    </NOSCRIPT>
    </BODY>
    </HTML> 
    PHP Code:

    <HTML>
    <
    HEAD><TITLE>Detecting the browser type</TITLE></HEAD>
    <
    BODY>
    <
    H3>Details of your browser</H3>
    <
    TABLE>
     <
    TR>
      <
    TD ALIGN="RIGHT">navigator.userAgent:</TD>
      <
    TD><B>
      <
    SCRIPT LANGUAGE="JavaScript">
      <!--
        
    document.write(navigator.userAgent)
      
    //-->
      
    </SCRIPT></B>
      </TD>
     </TR>
     <TR>
      <TD ALIGN="RIGHT">navigator.appName:</TD>
      <TD><B>
      <SCRIPT LANGUAGE="JavaScript">
      <!--
        document.write(navigator.appName)
      //-->
      </SCRIPT></B>
      </TD>
     </TR>
     <TR>
      <TD ALIGN="RIGHT">navigator.appVersion:</TD>
      <TD><B>
      <SCRIPT LANGUAGE="JavaScript">
      <!--
        document.write(navigator.appVersion)
      //-->
      </SCRIPT></B>
      </TD>
     </TR>
    </TABLE><P>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
      if (navigator.appName.indexOf('Netscape') != -1) {
        document.write('To upgrade your browser go to ' +
          '<A  HREF = "http://home.netscape.com/download/">' +
          'http://home.netscape.com/download/<\/A><\/P>');
        if (navigator.appVersion.substr(0, 1) > 3)
          document.write('You can use Netscape Dynamic HTML');
      }
      if (navigator.appName.indexOf('Microsoft') != -1) {
        document.write('To upgrade your browser go to ' +
          '<A  HREF = "http://www.microsoft.com/ie/">' + 
          'http://www.microsoft.com/ie/<\/A><\/P>');
        if (navigator.appVersion.substr(0, 1) > 3)
          document.write('You can use Microsoft Dynamic HTML');
      }
    //-->
    </SCRIPT>
    <NOSCRIPT>
      Sorry, your browser doesn't support client-side scripting, 
      so it can't display the details about your browser.
    </NOSCRIPT>
    </BODY>
    </HTML> 
    PHP Code:

    <SCRIPT LANGUAGE="JavaScript">
    <!--
      if (
    navigator.appName.indexOf('Netscape') != -1)
        if (
    navigator.appVersion.substr(01) > 3)
          
    window.location.href 'nav4_dhtml.htm'
        
    else
          
    window.location.href 'v3_with_script.htm';

      if (
    navigator.appName.indexOf('Microsoft') != -1)
        if (
    navigator.appVersion.substr(01) > 3)
          
    window.location.href 'ie4_dhtml.htm'
        
    else
          
    window.location.href 'v3_with_script.htm';
    //-->
    </SCRIPT>
    <NOSCRIPT>
      <!-- non script-enabled browser page contents go here -->
      <P>Welcome to our site</P>
      ...
    </NOSCRIPT> 

  15. #15
    SitePoint Enthusiast Incubator's Avatar
    Join Date
    Apr 2002
    Location
    Good old Belgium
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thnx alot andrew that extra script showed my mistake.
    It is indeed appVersion > 3 and not >5 as I thought
    Last edited by Incubator; Apr 12, 2002 at 17:47.
    "Press any key to continue. Press any other key to exit."


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •