/    Sign up×
Community /Pin to ProfileBookmark

Onclick Javascript Help

I’m trying to put together a function so that when a user clicks on an HREF (not a form) it will evaluate their platform and take them to the appropriate html page.

Here is the evaluation code in the HEAD:

<SCRIPT language=”JavaScript”><!–
function platformSniffer(macURL,os2URL,linuxURL,winURL) {
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_nav = ((agt.indexOf(‘mozilla’)!=-1) && (agt.indexOf(‘spoofer’)==-1)
&& (agt.indexOf(‘compatible’) == -1) && (agt.indexOf(‘opera’)==-1)
&& (agt.indexOf(‘webtv’)==-1));

var is_mac = (agt.indexOf(“mac”)!=-1);
var is_os2 = ((agt.indexOf(“os/2”)!=-1) ||
(navigator.appVersion.indexOf(“OS/2”)!=-1) ||
(agt.indexOf(“ibm-webexplorer”)!=-1));
var is_linux = (agt.indexOf(“inux”)!=-1);
var is_win = ( (agt.indexOf(“win”)!=-1) || (agt.indexOf(“16bit”)!=-1) );
var is_win95 = ((agt.indexOf(“win95”)!=-1) || (agt.indexOf(“windows 95”)!=-1));
var is_win16 = ((agt.indexOf(“win16”)!=-1) ||
(agt.indexOf(“16bit”)!=-1) || (agt.indexOf(“windows 3.1”)!=-1) ||
(agt.indexOf(“windows 16-bit”)!=-1) );
var is_win31 = ((agt.indexOf(“windows 3.1”)!=-1) || (agt.indexOf(“win16”)!=-1) ||
(agt.indexOf(“windows 16-bit”)!=-1));
var is_win98 = ((agt.indexOf(“win98”)!=-1) || (agt.indexOf(“windows 98”)!=-1));
var is_winnt = ((agt.indexOf(“winnt”)!=-1) || (agt.indexOf(“windows nt”)!=-1));
var is_win32 = (is_win95 || is_winnt || is_win98 ||
((is_major >= 4) && (navigator.platform == “Win32”)) ||
(agt.indexOf(“win32”)!=-1) || (agt.indexOf(“32bit”)!=-1));

if (is_mac) { // Macintosh
location.href = macURL;
} else if (is_os2) { // OS2

location.href = os2URL;
} else if (is_linux) { // Linux
location.href = linuxURL;
} else if (is_win || is_win95 || is_win98 || is_winnt || is_win31 || is_win32 || is_win16) {
location.href = winURL; // Windows
}
}
//–></SCRIPT>

And here is my HREF:

<A HREF=”#” onclick=”platformSniffer(‘intro_m.htm’,’intro.htm’,’intro.htm’,’intro.htm’)”>

Can anyone tell me why this won’t work?? Thanks for any help and assistance.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@CharlesFeb 10.2003 — [font=georgia]If all that you are sniffing for is the operating system then you are making way too much out of this. In either case you have forgotten about those of us who do not use JavaScript.[/font]

[font=monospace]<a href="default.html" onclick="url = {Win32:'Win32.html' , Win16:'win16.html' , MacPPC:'macppc.html'}[navigator.platform]; if (url) this.href = url">Click Me</a>[/font]
×

Success!

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