简体   繁体   中英

Check for internet explorer. PHP vs. ie conditional comments?

So I've decided to break up my CSS into an ie6-and-ie7-only file. I will have CSS rules in this file which target ie6 and ie7 only, such as:

div {
    *color: red; /* target ie7 and below */
    _color: green; /* target ie6 and below */
}

If possible, I prefer to use PHP with $_SERVER['HTTP_USER_AGENT'] to detect the browser, rather than ie conditional comments.

I understand that visitor can "spoof" their user-agent and claim to be whichever browser they want, but what is the general opinion on using PHP instead of ie conditional comments to detect the browser?

Do you want that string comparison each time a page is requested? I wouldn't. I'd leave this up to the browser.

IMHO - use IE conditional comments. they're pretty much faster as compared to processing on the server! Think about this if you have 100 clients processing this on your server, your server will be slowed compared to delegating to that 100 clients to render and process.

It's not worth the server load even if you cache it and not render it on server every time.

As an alternative, which has worked pretty well for me, you could use css_browser_selector.js . With it, your style sheet would look more like this:

.ie7 div {
    color: red; /* target ie7 */
}

.ie6 div {
    color: green; /* target ie6 */
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM