/    Sign up×
Community /Pin to ProfileBookmark

I new to java but how do you load different settings for different browers?

Let’s say i want the page to be font size 6 on FF but size 8 on IE. I know there is a code like “if firefox” but i’m not sure how to set it up.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@felgallJul 02.2007 — What size do you want it on all the hundreds of other browsers? In any case if you are sizing in pixels then it will appear differently depending on the resolution of the screen.

The only field for identifying which browser it is usually gets set to report all browsers as being Internet Explorer so as to bypass those scripts that try to process differently for different browsers.
Copy linkTweet thisAlerts:
@tivaelydocauthorJul 02.2007 — Well, I keep seeing coding like this:

"if (this.ie || this.firefox)" and other types where the website will load different settings for different browsers. This screen I made looks good on FF:

http://iloveruby.freehostia.com/binary.htm

but not on IE, but for IE, I could use this:

http://iloveruby.freehostia.com/binary2.htm

But it doesn't work on FF, so what should I do?
Copy linkTweet thisAlerts:
@felgallJul 02.2007 — That sort of code was common about 10 years ago for telling the difference between Netscape 3 and IE3. By the time IE5 came out all of the other browsers provided a way of identifying themselves as IE and such code to test what browser it was became completely useless.

Properly coded HTML and CSS will look similar on all browsers without needing special coding for any particular browser.
Copy linkTweet thisAlerts:
@tivaelydocauthorJul 02.2007 — That sounds completely right, but what about this kind of coding?

if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE6 or below


Isn't there some sort of way that the browser can tell the difference or something?

Why do those 2 pages show up different, but the codes are nearly the same?
Copy linkTweet thisAlerts:
@felgallJul 02.2007 — That is called feature sensing. You test if the browser supports a given feature before running it. The comments are only there to remind the author that IE6 and below do not support XMLHttpRequest and so the activeX version needs to be used instead. The comment doesn't mention that IE3 and earlier will also fail the second test (if it were actually coded properly to test for the specific activeX control that the code requires - which that version doesn't) and that there are many other old versions of just about every browser that exists that will also fail both tests.

Using feature sensing allows browsers to support the code that they recognise and ignore the code that they don't. With that particular example no code changes were required when IE7 was introduced in order for it to use the better method of processing (apart from someone having updated the comment in your example). Had it used browser sensing it would have been forced to use the less efficient method even though it now supports the mmore efficient one.
Copy linkTweet thisAlerts:
@tivaelydocauthorJul 02.2007 — Oh ok, I understand. I got to change the coding. Alright, thanks a lot.
×

Success!

Help @tivaelydoc 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.29,
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,
)...