/    Sign up×
Community /Pin to ProfileBookmark

What does this mean/do?

The following:


—————————————————————

<SCRIPT LANGUAGE=”JavaScript”><!–//
IE=(navigator.appName.indexOf(‘Microsoft’) >= 0);
NS=(navigator.appName.indexOf(‘Netscape’) >= 0);
V4=(parseInt(navigator.appVersion) >= 4);
V5=(parseInt(navigator.appVersion)>=5);
V5=(V5||navigator.appVersion.indexOf(“MSIE 5”)!=-1);
V5=(V5||navigator.appVersion.indexOf(“MSIE 6”)!=-1);
MAC=(navigator.userAgent.indexOf(‘Mac’)!=-1);//–>
</SCRIPT>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterMay 25.2005 — [color=royalblue]navigator.appName[/color] returns a big long string with brower information.

Next, Every string has access to the [color=royalblue]indexOf[/color] function.

[color=royalblue]navigator.appName.indexOf('Microsoft')[/color] returns a number.

If the string doesn't contain "Microsoft" then the number is set to -1.

If the string [i]does[/i] contain "Microsoft" then the number can be set from anything from 0 through infinite depending on where the segement is located in the string.

since [color=royalblue]navigator.appName.indexOf('Microsoft')[/color] returns a number,

[color=royalblue](navigator.appName.indexOf('Microsoft') >= 0);[/color]

returns either true or false

Thus, the variable [b]IE[/b] will be set to either true or false.
Copy linkTweet thisAlerts:
@phpnoviceMay 25.2005 — Nice description of what it [b][U]does[/U][/b] -- but not what it [b][U]means[/U][/b]. That code is called [I]"platform and browser sniffing"[/I] -- a.k.a., [I]"client sniffing"[/I]. It's purpose is to allow script to provide different logic branches depending upon the platform on which and the browser in which the script is running. To put that another way, it allows a script to function cross-platform and cross-browser in nearly the same fashion.

The following is out of date, but it gives you an idea of the complexity and the art of browser sniffing:

[URL=http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html]Ultimate JavaScript Browser Sniffer[/URL]
Copy linkTweet thisAlerts:
@Chris_2authorMay 25.2005 — thanks guys, I now understand it much better ?
×

Success!

Help @Chris_2 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.2,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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