...

View Full Version : Hiding javascript from Mac Browser



Asterisk
12-30-2003, 06:23 PM
I have a script that is too slow on Mac browsers and would like to hide it from them and provide a different one.
Can anyone tell me how to alter this script to accomplish that? I got it from PerlScriptsJavaScripts.com and it helps me sniff the browser but I don't know how to

<script>
<!--
v3 = 0; op = 0; ie4 = 0; ie5 = 0; nn4 = 0; nn6 = 0; isMac = 0; aol = 0;

if(document.images){
if(navigator.userAgent.indexOf("Opera") != -1){
op = 1;
} else {
if(navigator.userAgent.indexOf("AOL") != -1){
aol = 1;
} else {
ie4 = (document.all && !document.getElementById);
nn4 = (document.layers);
ie5 = (document.all && document.getElementById);
nn6 = (document.addEventListener);
}
}
} else {
v3 = 1;
}

if(navigator.userAgent.indexOf("Mac") != -1){
isMac = 1;
}

// -->
</script>
<script>
<!--

if(op){ // do this
alert("You are using Opera");// I'd like this to instead load menu_array.js
}
if(ie4){ // do this
alert("You are using Internet Explorer 4");// I'd like this to instead load menu_array.js
}
if(ie5){ // do this
alert("You are using Internet Explorer 5 or above");// I'd like this to load menu_array.js
}
if(nn4){ // do this
alert("You are using Netscape 4");// I'd like this to instead load menu_array.js
}
if(nn6){ // do this
alert("You are using Netscape 6");// I'd like this to instead load menu_array.js
}
if(aol){ // do this
alert("You are using an AOL browser");// I'd like this to instead load menu_array.js
}
if(v3){ // do this
alert("You are using a pre version 4 browser");// I'd like this to instead load menu_array.js
}
if(isMac){ // do this
alert("You are using a Macintosh browser");// I'd like this to instead load menuMac_array.js
}

// -->
</script>

Skyzyx
12-31-2003, 12:29 AM
Okay, what exactly are you trying to do? Are you using .js files? Is this an all-in-one script? It makes a difference.

Asterisk
12-31-2003, 12:39 AM
Thank you so much for replying.

The site I'm working on has several javascript navigation menus.
The javascript is referenced to separate files.

I want everyone but mac users to see the javascript as it is.
I want the Mac users to see a simplified version which I haven't developed yet. I'd rather not create separate Mac HTML.

Client Site (http://www.paperdirect.com)

Skyzyx
12-31-2003, 01:13 AM
Well, I'll give you two answers:

If you want to sniff for Macs (I assume you're talking about all Mac browsers, and not just Mac IE...), you could use something like this:




if (navigator.useragent.toLowerCase().indexOf('mac') != -1)
{
Do Mac stuff....
}
else
{
Do Windows/Linux/Unix/BeOS/All other OS's stuff...
}



However, If you want a simpler script that works flawlessly in every browser I've tried, check out Brothercake's List-Based Menus (http://www.codingforums.com/showthread.php?s=&threadid=19289). I've used it for a few of the sites I've worked on recently, and they're brilliant! They also downgrade, are standards-compliant, semantic, and all sorts of other good stuff! :thumbsup:

Either way is up to you, but I'd definitely recommend Brothercake's script.

Asterisk
12-31-2003, 01:21 AM
You are all that and a biggie-sized fry.

I'll go to work reworking the navigation tonight.

Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum