/    Sign up×
Community /Pin to ProfileBookmark

help!! browser detection woes…

i am a relative newbie and am trying out some basic scripts and was wondering what the general consensus is when trying to detect the browser type.
I have been trying to use the if (document.all){do this} else if (document.layers){do that} method and after puzzling for a while i found my netscape 7 will not take this method, if i remove the if(document.layers) leaving the else {do that} it works fine, but is this a good idea??
Anyways, is this method an outdated method as I learnt it from quite an old tutorial??
What is the predominant method for browser detection??

ps-heres my script that won’t work in case there is a prob

<HTML>
<HEAD>
<script language=”javascript”>
function doit() {
if (document.layers){
alert(“netscape”);}
else if (document.all){
alert(“IE”);}
}
</script>

</HEAD>
<BODY>
<body onload=doit();>

</body>
</HTML>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@VladdyApr 01.2004 — Nowadays the only approach to scripting that has positive ROI is:

if(document.getElementById)

{ /* run scripts */

}

/* else the user gets the page without javascript enchancements */
Copy linkTweet thisAlerts:
@fredmvApr 01.2004 — I fully agree with Vlad, though I'd probably write it like this:if(typeof document.getElementById != 'undefined')
{
// ...
}
×

Success!

Help @stunews 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...