Javascript Problem

Discussion in 'Software' started by Kevyn, Sep 5, 2005.

  1. Kevyn

    Kevyn Private E-2

    Hi all,

    Well, I'm a total beginner in programming. I wanted some sort of script on my website that would redirect people if they used a certain browser (Firefox and Opera) and let people through if they were using Internet Explorer. (Before you guys go bashing me for doing this, it's only because my website looks horrible in Firefox and Opera.) Here's what I have so far:

    Code:
    <script language="javascript">
    <!--
    if (navigator.appName == "Mozilla Firefox") {
            document.location.replace('REDIRECTION SITE 1');
    }
    if (navigator.appName == "Opera") {
            document.location.replace('REDIRECTION SITE 2');
    }
    else { 
            document.write('<!--IE-->')
    }
    // -->
    </script>
    The script works perfectly in Internet Explorer and Opera, but has no effect in Firefox. I've heard that using navigator.appName is a bad way of detecting what broswer the user is using, but I don't know any other ways. Any and all help is appreciated. Thanks! :)
     
  2. elMaco

    elMaco Private E-2

    Hi

    remove Mozilla from the script, ypu only need ("Firefox")

    it should work
     
  3. elMaco

    elMaco Private E-2

    but i should use:

    if(navigator.userAgent.indexOf("Firefox") != -1)
    {
    window.location = "page one here";
    }
    else
    {
    window.location = "page two here";
    }
     
  4. Kevyn

    Kevyn Private E-2

    Thanks for the help, guys.

    But I got it to work by replacing "Mozilla Firefox" with "Netscape", since, for some reason, "Netscape" is used as Firefox's appName string.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds