28, May 2012

browser detection css output with php - IE hacks - methods you use - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: browser detection css output with php - IE hacks - methods you use
« previous next »
Pages: [1] Print
Instabuck - The easy way to sell digital products online

Author Topic: browser detection css output with php - IE hacks - methods you use  (Read 947 times)
My Name is Enigo Montoya
*
Posts: 33
188 credits
Members referred : 0


« on: Dec 27, 2006, 08:24:09 am »

I came across a site the other day, and it showed a valid css link and it did validate correctly.  I am a Firefox user, but when viewing it in IE however it showed colored scrollbars...colored scrollbars aren't a big deal since it isn't valid code anyway, but I wondered how it was included.  After looking a little further there is a main stylesheet that contains everything along with the following code being used...
Code:
<script type="text/javascript">
// <![CDATA[
if (document.all) {
    var vIE = '\n<style type="text/css">\n@import url("cssjs/bgs_ie.css");\n</style>\n';
    document.write(vIE);
}
// ]]>
</script>
So I thought that this might be a clever way to include IE "hacks" such as how the box model doesn't render properly in IE, padding is interpreted differently and well you get the idea  Grin  Although I don't use IE, many people do and when building sites this is something to consider.  Now to my question...in the unlikely event that a user has javascript disabled I want to be able to translate this into php.  I'll post a few links I found since they may help others that may want to expirement...but most are much more than I would need.

http://www.digitalbonsai.com/phpstyle.php http://www.stylegala.com/articles/no_more_css_hacks.htm

I also found http://www.sitepoint.com/article/browsers-suck-php-rescue and thought that maybe I could change this section of code...
Code:
<?php
if (!(strpos($HTTP_USER_AGENT,'Mozilla/5') === false)) {
 echo(
"<!-- Netscape 6 specific code -->");
} else {
 echo(
"<!-- Code for other browsers -->");
}
?>
but this is more for specific sections of your layout and code .  Any suggestions on code to detect IE and show that stylesheet?  As when you "include" the css file it only renders the text of course.  I found where someone also suggested using the "@ import" in php and
Code:
@ require_once ('style.css');
produces the same.

Essentially, I would like the main stylesheet with everything in it...if php detects IE as browser, show that IE stylesheet with all the included fixes so it shows correctly.  Would be nice if I might be able to add to it...so if I saw a bug in some other browser on a site I was building I could also say if browser is whatever include that stylesheet.  I was just thinking that there might be a better way to hack your css rather that having to include !important all over your existing stylesheet so it only looks for certain things in IE.(might help to keep it clean and organized, if it got really big with many many classes)

Thank you, Brad
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #1 on: Dec 27, 2006, 08:45:52 am »

That was a big post, and yet I am not sure if I understand what you want... Maybe I should drink my first coffee and come back again Smiley

Anyway if you want to check for IE you can try this :

if ( ! (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') === false) )
    echo 
'Hello, you are using a buggy browser'
?>

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
My Name is Enigo Montoya
*
Posts: 33
188 credits
Members referred : 0


« Reply #2 on: Dec 27, 2006, 07:12:34 pm »

Sorry for the long post...I tried to include too much into it.  I think I found a solution going on what you posted.  I wanted to be able to include an IE specific stylesheet when it was determined that the browser was in fact IE.
Code:
<?php
if ( ! (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') === false) )
    echo '<link rel="stylesheet" type="text/css" href="ie.css">';

?>
I will have say for instance <link rel="stylesheet" type="text/css" href="main.css"> in my code near the top...where main.css controls everything and the above code will go towards the end of my page so it renders later on in the browser.  That way if the above code picks up that the browser is IE it will add the additional <link rel="stylesheet" type="text/css" href="ie.css"> later on and this will hopefully fix bugs and there won't be any css inherit issues since ie.css comes after main.css.  As far as I can tell, this will work since the code is rendered top to bottom.

I had previously made the mistake of what needed to go into the echo statement as far as trying to include the additional IE stylesheet.

Thanks again  Smiley
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #3 on: Dec 27, 2006, 08:15:25 pm »

Yeah the way you are doing it now, is much more professional and easier to remember in the future.

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
My Name is Enigo Montoya
*
Posts: 33
188 credits
Members referred : 0


« Reply #4 on: Dec 27, 2006, 09:34:08 pm »

I agree, and it is easy and compact enough, that by some chance if I spotted an unusual error in another browser say like opera...I would be able to use that same code with opera detection and include that stylesheet. 

As always thank you for the help, I appreciate it!
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=5381
Tags : Ie hacks css browser detection Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: browser detection css output with php - IE hacks - methods you use
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 07:19:57 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.