www.webdeveloper.com
Results 1 to 9 of 9

Thread: Need some help here :(

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    4

    Need some help here :(

    I'm making a website that contains CSS that only works in Firefox 3.5+ and Safari 4+

    I would like to redirect people to my home.htm if they have either FF 3.5+ or Safari 4+.

    If they have any other kind of browser or version, I would like them redirected to sorry.htm

    I managed to get hold of a script that should do this, but it doesn't appear to work.

    Here it is:

    Code:
    <script>
    var browser_type=navigator.appName
    var browser_version=parseInt(navigator.appVersion)
    if (browser_type=="Firefox"&&browser_version>=3.5)
    window.location.replace("home.htm")
    else if (browser_type=="Safari"&&browser_version>=4)
    window.location.replace("home.htm")
    else
    window.location="sorry.htm"
    </script>
    I've put this in the <head> section.

    However, when I try it in my browser (Firefox 3.5.3) it takes me to sorry.htm
    And when I try it in Safari 4.0.2 it also takes me to sorry.htm

    How come this doesn't work? Can anybody help me with this?

    Thanks in advance! I appreciate your time ^_^

  2. #2
    Join Date
    Aug 2008
    Location
    Longmont CO
    Posts
    47
    For my browser (Firefox 3.0.14) it actually returns "Mozilla" and version 5.

    You might try dropping alerts(); into your code to see what Javascript is telling you.

    Carl

  3. #3
    Join Date
    Oct 2008
    Location
    U.S.
    Posts
    726
    I'm making a website that contains CSS that only works in Firefox 3.5+ and Safari 4+

    I would like to redirect people to my home.htm if they have either FF 3.5+ or Safari 4+.

    If they have any other kind of browser or version, I would like them redirected to sorry.htm
    You are going about this all wrong. Javascript and redirecting is NOT the correct solution here, the solution is to fix the css (without javascript!) to work in IE as well as FF & Safari. Believe it or not, it can be done relatively easily and is not really as hard as the javascript solution.

  4. #4
    Join Date
    Sep 2008
    Location
    Mexico
    Posts
    786
    If your really want to keep out certain browsers it would be best to do it server side... javascript can be turned off. I redirect cellphones / handhelds to special pages that way. But of course if you want everybody to see your pages, then astupidname is right... FIX the css.
    ...but stupidity is terminal.

  5. #5
    Join Date
    Oct 2009
    Posts
    4
    Thanks for the quick replies. I want everyone to have a chance to see my site, but I would like them to know them to know that some CSS is not supported by other browsers than Firefox and safari. This is in sorry.htm, along with a "show me the website anyway"-button. I can't fix the CSS, because there are no alternatives. Believe me, I've tried.

    I would like help with this script, and not tips to avoiding it.

    I hope that you understand.

    /etherflame

  6. #6
    Join Date
    Apr 2006
    Location
    Houston
    Posts
    1,374
    Quote Originally Posted by etherflame View Post
    ..I want everyone to have a chance to see my site, but I would like them to know them to know that some CSS is not supported by other browsers than Firefox and safari...
    Except for possibly Chrome, Opera 10, or IE 9 - which will never have a chance to run the CSS on your page because you will be re-directing them without giving them the chance.

    The best way is to have a page that functions in all browsers. If a browser does not support the super cool stuff, then they'll never know it, because they will just never see it.

    If you really just want to detect for IE then you may want to go with the CSS conditional comments trick: http://www.quirksmode.org/css/condcom.html
    or other CSS hacks: http://www.quirksmode.org/css/csshacks.html

    (really recommend against that though)

  7. #7
    Join Date
    Oct 2009
    Posts
    4
    How do you do this server side redirection?

  8. #8
    Join Date
    Sep 2008
    Location
    Mexico
    Posts
    786

    User Agent strings

    There are ALWAYS alternatives! CSS is the answer to rendering you pages cross-browser... even if a browser doesn't support something there are usually similar acceptable solutions for troublesome browsers. And there are a lot mor browsers than just IE, Firefox and Safari.... not a good idea to check them by "name" check by name / type. I am using a dev version of Firefox... it doesn't say firefox... it says Shiretoko, but uses the Gecko engine so you have to check for the engine that is the same.

    For server side browser redirection or content replacement, I use PHP
    PHP Code:
    <?php
    $d 
    detect();
    $b $d['browser'];
    $v $d['version'];
    $o $d['os'];
    function 
    detect()
        {
        
    $browser = array ("IE","OPERA","MOZILLA","NETSCAPE","GECKO","FIREFOX","SAFARI","CHROME","BLACKBERRY");
        
    $os = array ("WIN","MAC","LINUX","ANDROID","BSD","SOLARIS","IPHONE");
        
    $info['browser'] = "OTHER";
        
    $info['os'] = "OTHER";
        foreach (
    $browser as $parent)
            {
            
    $s strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent);
            
    $f $s strlen($parent);
            
    $version substr($_SERVER['HTTP_USER_AGENT'], $f5);
            
    $version preg_replace('/[^0-9,.]/','',$version);
            if (
    $s)
                {
                
    $info['browser'] = $parent;
                
    $info['version'] = $version;
                }
            }
        foreach (
    $os as $val)
            {
            if (
    eregi($val,strtoupper($_SERVER['HTTP_USER_AGENT']))) $info['os'] = $val;
            }
        return 
    $info;
        } 

        if (
    $o == "OTHER" && $b == "OTHER") {
    echo 
    " something for unsupported os and unsupported browser";
            } else {

    echo 
    "something for everybody else ";
     }    

    ?>
    This sample contains most of the options you might need... just change it to suit your needs. But remember, the User Agent string CAN be faked in various ways by the user. More info on User Agent strings.
    ...but stupidity is terminal.

  9. #9
    Join Date
    Oct 2009
    Posts
    4
    Thanks guys. I'll try spending the weekend fixing the CSS.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles