Hello and welcome to the Webmasters Forums!. This is the best place to get webmasters resources for free. Get $2 for free today, read more - Make your payment today. Download premium and professional templates for free. Get free web hosting without ads, read more. You can get lot more by simply join with this forum. To gain full access to the forums you must sign up for a free account.


Post Reply  Post Thread 

Browser-specific code

Post Bank
Posting Manager
******

Posts: 995
Group: Forum Team
Joined: Sep 2006
Status: Online
Download FileShield free from PermissionResearch!
Make money from now. You can make money just for posting on this forum. Every discussions on this community gives you more money. $2 minimum payout. So get your payment today, SignIn with this forum.

Signin to Remove this Post

bomber
Junior Member
*


Posts: 34
Group: Registered
Joined: Sep 2006
Status: Offline
Reputation: 0
Points: 250 (Donate)
Post: #1

Big Grin Browser-specific code


Sometimes when you're writing HTML you'll find yourself in a situation where the code you want to use will only work on one browser (and we all know which browser that is). Not only won't it work on other browsers, but one specific browser (and we all know which that is) crashes and burns, or won't show the page at all. In this case you can detect the browser with PHP and only show the dodgy code on IE, or show something else on Netscape.

Whenever a browser asks a webserver for a page, it presents some information to the server (like which page it wants, and what browser it is.. ) and PHP turns this information into variables when it loads. Check out the $_SERVER['HTTP_USER_AGENT '] variable; it contains the name and version of the browser. The problematic browser, especially regarding Cascading Style-sheet bugs is Netscape 4, between 4.1 and 4.8 . We don't include 4.0 because that's what Internet explorer pretends to be.

So now, in your HTML code, or in your style-sheet if you keep them separate:

PHP Code:
<style type="text/css">
   <!--
   <?  
// Browser check: Netscape 4.x can't deal with borders on CSS elements
   
     
if (!eregi("^Mozilla/4.[1-8]"$_SERVER['HTTP_USER_AGENT'])) {
        
$css_border "border: 1px #FFFFFF solid;";
     } else {
        
$css_border "";
     }

   
?>
   SELECT  {
           background:  #002F54;
           color: #FFFFFF;
           font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
           font-size: 10pt;
           <?=$css_border?>
   }
   --></STYLE> 

18-09-2006 11:44 PM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites
Rate This Thread:

Forum Jump:

Sign In to Remove Ads

Download 1000's of web templates. Unlimited access!
World's Best Web Hosting
Resources

Recommended Sites:



Visit our Sponsors!

Current time: 06-01-2009, 05:11 PM


Copyright © 2002-2009 MyBB Group
Powered By MyBB