browser check for style question 
Author Message
 browser check for style question

I've spent quite a bit of time researching this question and cannot find a
solid answer. My question is about directing users to the appropriately
styled site for their browser type.  I have found the following snippet (in
this groups archive in Google) which seems to make sense in general but I am
having trouble utilizing it specifically.  First off, here is the snippet:

<?php
 $browser_type = $_SERVER['HTTP_USER_AGENT'];
 if ($browser_type == "??NN 4.x??")
  {
    header("Location: your_url_path");
  } else {
    header("Location: your_other_url_path");
  }
?>

I would like to direct  NN 4.x users to a compatible style sheet and others
to another stylesheet.  (I know, I know, but the person I'm building the
site for wants it compatible with NN 4/x and I would rather not use the
import workaround)

First off how would I define browser type to reflect NN 4/x?  Next, I can
only figure that the above snippet would be the only code in my index page,
and the redirect would happen from there, but that doesn't seem quite right.

I guess the other option is the redirect would be to the stylesheet url's,
but that opens up a whole new batch of questions, biggest being how would I
make the correct CSS declaration in the <head>?

Any help would be much appreciated, even if it is another solution that gets
the desired results.

Mike



Wed, 18 May 2005 14:36:00 GMT  
 browser check for style question
hi Mike,

Quote:

> I've spent quite a bit of time researching this question and cannot find a
> solid answer. My question is about directing users to the appropriately
> styled site for their browser type.  I have found the following snippet (in
> this groups archive in Google) which seems to make sense in general but I am
> having trouble utilizing it specifically.  First off, here is the snippet:

> <?php
>  $browser_type = $_SERVER['HTTP_USER_AGENT'];
>  if ($browser_type == "??NN 4.x??")
>   {
>     header("Location: your_url_path");
>   } else {
>     header("Location: your_other_url_path");
>   }
> ?>

> I would like to direct  NN 4.x users to a compatible style sheet and others
> to another stylesheet.  (I know, I know, but the person I'm building the
> site for wants it compatible with NN 4/x and I would rather not use the
> import workaround)

> First off how would I define browser type to reflect NN 4/x?  Next, I can
> only figure that the above snippet would be the only code in my index page,
> and the redirect would happen from there, but that doesn't seem quite right.

> I guess the other option is the redirect would be to the stylesheet url's,
> but that opens up a whole new batch of questions, biggest being how would I
> make the correct CSS declaration in the <head>?

> Any help would be much appreciated, even if it is another solution that gets
> the desired results.

> Mike

It's not a PHP solution, but I've used the following Javascript in the
head element of an HTML page to point to the appropriate stylesheet:

     <script language="javascript">
         <!--
             browser_version= parseInt(navigator.appVersion);
             browser_type = navigator.appName;

             if (browser_type == "Netscape" && (browser_version >= 4) &&
(browser_version < 5)) {
               document.write("<link type='text/css' rel='stylesheet'
href='../styles/netscape4style.css' type='text/css' />");
             }
             else  {
               document.write("<link type='text/css' rel='stylesheet'
href='../styles/otherstyle.css' />");
             }
         // -->
     </script>

To do it with PHP, you could just do the test first to see if it is
Netscape 4.x that you're dealing with, and have a boolean value,
$isNetscape, that's set to true if it's NN4.x or false otherwise, then
put the following in your page in the head element:

<link type='text/css' rel='stylesheet' href="<?= $isNetscape ?
'path-to-netscape-style.css' : 'path-to-other-style.css'; ?>" />

Hope this helps,

jano



Wed, 18 May 2005 17:24:18 GMT  
 browser check for style question

Quote:

> I've spent quite a bit of time researching this question and cannot find a
> solid answer. My question is about directing users to the appropriately
> styled site for their browser type.  I have found the following snippet
> (in this groups archive in Google) which seems to make sense in general
> but I am
> having trouble utilizing it specifically.  

S{*filter*}this - simply make your CSS file a PHP page, and put the logic to
choose the correct style rules in the php page itself. Have this in the
<head> of the document:

<link rel="stylesheet" href="mystyle.php"/>

and make sure you change the mime type of the php page before outputting
any data to the browser..

so.. mystyle.php

<?php
header('mime-type','text/css');
//logic to sniff NN
if (....
  $shiteNN = TRUE;

Quote:
}

?>
body{
  some rules...
  <?php if ($shiteNN){?>
     some NN specific rules..
  <?php } ?>

Quote:
}

This way means you only have 1 stylesheet to maintain - maintaining more
than one CSS file kinda defeats the object of CSS.

HTH

How

http://www.*-*-*.com/



Wed, 18 May 2005 20:46:41 GMT  
 browser check for style question

Quote:

> > I've spent quite a bit of time researching this question and cannot find
a
> > solid answer. My question is about directing users to the appropriately
> > styled site for their browser type.  I have found the following snippet
> > (in this groups archive in Google) which seems to make sense in general
> > but I am
> > having trouble utilizing it specifically.

> S{*filter*}this - simply make your CSS file a PHP page, and put the logic to
> choose the correct style rules in the php page itself. Have this in the
> <head> of the document:

> <link rel="stylesheet" href="mystyle.php"/>

> and make sure you change the mime type of the php page before outputting
> any data to the browser..

> so.. mystyle.php

> <?php
> header('mime-type','text/css');
> //logic to sniff NN
> if (....
>   $shiteNN = TRUE;
> }
> ?>
> body{
>   some rules...
>   <?php if ($shiteNN){?>
>      some NN specific rules..
>   <?php } ?>

> }

> This way means you only have 1 stylesheet to maintain - maintaining more
> than one CSS file kinda defeats the object of CSS.

*Thank you* for the information.  This seems to be an option worth perusing.
I like the server-side solution better than the .js but I do appreciate all
replies.  I have some, but very rudimentary training in PHP and to be honest
I'm having trouble following along with the above code.  Here is my
interpretation, but please correct me if I am wrong.  All screwups are from
my inexperience and not Howard's help above.  I'm sure it makes perfect
sense to those who actually know what they are doing :)

<?PHP
header('mime-type', 'text/css')'
 $browser_type = $_SERVER['HTTP_USER_AGENT'];

if {

    $browser_type == "Mozilla && (browser_version >= 4 && (browser_version <
5));
/*ADD CSS BLOCK FOR NETSCAPE 4/x*/

Quote:
} else {

    $browser_type ==  "Mozilla && (browser_version > 5);
/*ADD OTHER CSS BLOCK*/

Quote:
}

?>

One of my main questions is how to differentiate between Netscape 4/x and
the rest of the browser world.  For some reason this should be easy to find
through Google but I can't seem to frame a specific query to dig down far
enough for it.

Thanks again,
Mike



Thu, 19 May 2005 14:04:00 GMT  
 browser check for style question

Quote:

> One of my main questions is how to differentiate between Netscape 4/x and
> the rest of the browser world.  For some reason this should be easy to find
> through Google but I can't seem to frame a specific query to dig down far
> enough for it.

Here is a good example...I use a similar method to this:
http://groups.google.com/groups?lr=&ie=UTF-8&oe=UTF-8&selm=009e01c05d...

The short answer is that there is no way to exactly match NN 4.x.
However, using this example you can match IE, Mozilla, NN 6.x, etc, and
then declare everything else to be NN 4.x.



Fri, 20 May 2005 14:38:21 GMT  
 browser check for style question


: I've spent quite a bit of time researching this question and cannot find
a
: solid answer. My question is about directing users to the appropriately
: styled site for their browser type.  I have found the following snippet
(in
: this groups archive in Google) which seems to make sense in general but
I am
: having trouble utilizing it specifically.  First off, here is the
snippet:
:
: I would like to direct  NN 4.x users to a compatible style sheet and
others
: to another stylesheet.  (I know, I know, but the person I'm building the
: site for wants it compatible with NN 4/x and I would rather not use the
: import workaround)

Browser sniffing is fraught, especially client side but server side as
well.  There are other more "reliable" methods however.


to have a linked style sheet (covering cross browser declarations) that
import a style sheet covering non NS4 declarations.  See
http://www.ericmeyeroncss.com/bonus/trick-hide.html

Louise



Fri, 20 May 2005 19:29:41 GMT  
 browser check for style question

Quote:
> One of my main questions is how to differentiate between Netscape 4/x and
> the rest of the browser world.  For some reason this should be easy to
find
> through Google but I can't seem to frame a specific query to dig down far
> enough for it.

> Thanks again,
> Mike


browser sniffing have their fair share of anomalies.  Not sure what to do,
but the help is appreciated.  Gave me a lot of directions for research.

Mike



Sun, 22 May 2005 03:23:36 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Procedural style to functional style question

2. Smalltalk style class browser for python

3. Support for filetypes in Motif style file browser

4. Mac style directory browser

5. Listbox - Style check box problem

6. Style Guide Checking Tool

7. Specific use of GNAT style checking

8. Help : GNAT Style checking

9. array argument checking style issue

10. autoconf-style checking for installed libs with DistUtils

11. Help: How to make validation check working on Edit-in-place of a browser

12. Browsers, browsers, browsers

 

 
Powered by phpBB® Forum Software