FRIHOSTFORUMSSEARCHFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

browser differences, etc

 


Olivia Wood
So I heard there is a way to make a website run from different code depending on what browser and/or resolution a viewer is using. Like it would be redirected or something. Is this true?

If so, would I be able to do this, and how would I be able to do this? *looks around hopefully*

If not, how tacky would it be for me to have one of those welcome pages where you choose your browser manually? Because as much as I really, really hate those things and am trying to make my site professional looking, the browser-compromise thing really, really, really isn't working for me. Crying or Very sad
Stubru Freak
First: try to use xhtml/css
That will increase cross-browser compatibility.

Second: you can easily retrieve the user's browser in php with this script:

Quote:
Code:
function _get_browser()
{
  $browser = array ( //reversed array
   "OPERA",
   "MSIE",            // parent
   "NETSCAPE",
   "FIREFOX",
   "SAFARI",
   "KONQUEROR",
   "MOZILLA"        // parent
  );
 
  $info[browser] = "OTHER";
 
  foreach ($browser as $parent)
  {
   if ( ($s = strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent)) !== FALSE )
   {           
     $f = $s + strlen($parent);
     $version = substr($_SERVER['HTTP_USER_AGENT'], $f, 5);
     $version = preg_replace('/[^0-9,.]/','',$version);
             
     $info[Browser] = $parent;
     $info[Version] = $version;
     break; // first match wins
   }
  }
 
  return $info;
}


If you do $browser = _get_browser();
$browser["Browser"] will contain the user's browser and $browser["Version"] will contain the version number of the browser

So then you can do
Code:
if($browser["Browser"] == "MSIE"){
echo "IE only!";
} else if($browser["Browser"] == "FIREFOX"){
echo "At least you use a good browser!";
} else {
echo "Which browser are you using that even MY site doesn't recognise it?";
}
riv
I would not recommend multiple pages, because then you'll have to seperately edit all the HTML files or have PHP include() rules, and it gets really inconvenient, not to mention annoying.

Because I don't know what your website is like and what it's like under the hood, and wether or not you're using tables for layout, and CSS for just FAC (fonts and colour), I'll just assume that you are a good webmaster and use CSS design. (If you don't, you should really consider it.)

Anyways, I would recommend that you use advanced CSS rules in your CSS that older browsers (such as the older IE's, Netscape, and all those horrors of the web) doesn't understand or doesn't parse correctly, so as to make the user agent just skip the rule(s).

Here are some (well, 2) options:
Code:

html > body #something {
 /* this will all be skipped */
}
#something_else {
 background: yellow;
 voice-family: "\"}\"";
 /* this will be skipped, while the upper part won't */
}

There are many other methods of skipping rules, consider searching the internet.
SystemWisdom
riv wrote:

Code:

html > body #something {
 /* this will all be skipped */
}


This is a good example, as it is a valid child selector rule and will not break in future browsers, however the following could potentially break in future browsers when the CSS parsing engine is updated:

riv wrote:

Code:

#something_else {
 background: yellow;
 voice-family: "\"}\"";
 /* this will be skipped, while the upper part won't */
}


The above uses a "hack" method to fool browsers that parse the CSS incorrectly (namely IE) and therefore the code following the hack isn't interpreted. But, it is possible that future versions of the "broken browser" will update their CSS parser and correct this mistake, rendering all code that uses it "broken" instead.

I don't recommend using "hacks" to differentiate between browsers, or you will find yourself updating your code whenever a browser fixes its renderer. If you don't mind that, then feel free! I consider it a means to experiment with the future possibilities of CSS until all browsers finally have working CSS Parsers. Then we won't need these hacks at all, and people will take to CSS a lot more seriously.
riv_
If you start with good valid markup and CSS, there isn't usually much difference between browsers. The differences that do appear can be worked out; there are tonnes of good resources for that.
But I don't know if they'd help you now, or not.
Really, as others in this thread have suggested, the best way to achieve a consistent cross-browser design, is to start with a standards-compiant markup, and css. (tables just won't do!)
I wish you luck! And please let us know if you need more resources, or have specific questions.
Related topics

--4000frih$ Website Project!!-- Needed Urgently!
AIM Mail
is there any way to trigger a .php file without refreshing?
(official) IE 7 Topic
Need a forum signature script, (php functions req)

xHTML what the heck
Html page or Flash?
Do you think IE 7 (not the beta) will be better then firefox
Is it possible that you HURT sm1 coz of YOUR LOVE 4 him/her
Which of these layouts is good?

Firefox vs IE ?
How do I make websites compatible to all browsers?
which is the best Digital Cammera?
Windows Vista - Official Thread
css in firefox vs. ie
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.