Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Change Code for specific browsers

    Hey

    Im aiming my site for firefox and ie but have found i need to change the code appropriately according to the diff browser. Is it possible to detect what browser the user is using and use the code I set for that browser on that page. For example if the browser used is firefox the browser will only use the code i set for firefox and vice versa.

    thanks

    vorl

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Yep, it sure is. It's often called code forking, you really want to do it as little as possible. Most people will test for a property or method that is only available in a certain browser.

    For example:

    Code:
    var ie=document.all;
    
    if(ie)
    {
     do ie stuff
    }
    else
    {
     do this stuff
    }
    More appropriatly to test for IE (sometimes opera will disguise itself as IE):

    Code:
    var ie=(document.all && !window.opera)?1:0;
    if(ie)
    {
     do ie stuff
    }
    else
    {
     do this stuff
    }
    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    25
    Thanked 0 Times in 0 Posts
    hi Basscyst

    thanks for the response. would doing this slow down the loading of the page?

    also could you show me how to detect firefox?

    thanks for the help

    vorl

  • #4
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    899
    Thanks
    0
    Thanked 118 Times in 117 Posts
    var ff=(navigator.userAgent.indexOf('Firefox')!=-1?1:0);


  •  

    Posting Permissions

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