/    Sign up×
Community /Pin to ProfileBookmark

IE 6, IE7 , FireFox Script

Is there a javascript that can detect what browser a person is viewing the web page with then attach a CSS style sheet, accordingly? IE6 applies CSS rules differently than IE7 and FireFox is reason asked.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorJan 14.2007 — The logical and professional way is the opposite: to build your pages in the most standard and common way (HTML, CSS) so that at least the navigational and informational tasks of your page should work in all the browsers.

Most of the time you don't need to use some features/property/methods (CSS, javascript) which are specific for a certain browser but will fail in others. But even if there might be such a need, you may solve that locally, using some new code lines, instead of building 2-3 different external CSS or javascript files for each browser...

What you will suppose to do if the next year Microsoft will launch IE 8? Or Mozilla will change the name of the FF browser?

Always try to detect methods instead of browser's type, and than code accordingly. Browsers might change easily, methods hardly.
Copy linkTweet thisAlerts:
@coppocksJan 14.2007 — I would suggest that you take a look at this:

http://www.webreference.com/tools/browser/javascript.html

This can do most of your detection work for you. Then you would perform a document.write with JavaScript for your style references. However, you still need to have a global style reference within a <noscript> tag to accommodate anyone that might have JavaScript turned off.

Additionally, what you're attempting to do here by incorporating code based on browser types & versions, is generally considered bad practice. There are so few discrepancies between these browsers that proper coding can generally overcome them.
×

Success!

Help @7Changedotcom spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...