View Full Version : Redirecting in accorance to browser...

04-11-2003, 08:10 PM
Hey all,

I am in an icky situation at the moment.

Basically to the point, I have a menu. In different browsers, it appears in different places, not much that I can do about it, seeing as it is (as far as I am aware) all to do with the way that the browser interprets the code and that.

Anyway, I need to, because of this I need to put up a certain menu depending upon the browser used, e.g. if it is Mozilla, it would go to moz_menu.js, and Opera would go to op_menu.js, and so on.

Any help would be appreciated all.

I am pretty sure that I have the right forum, because I think it is a javascript that will help do this; if not just do your thang mods. :D



04-11-2003, 08:57 PM
You need to parse the userAgent string to differentiate between browsers. For example:

var ua=navigator.userAgent;

// Internet Explorer 5 or greater. Spoof-proof for Opera.
var brIE5=(ua.indexOf('MSIE') != -1 && parseInt(ua.split('MSIE ')[1]) >= 5 && ua.indexOf('Opera') == -1) ? true:false;

// Any Gecko Browser, including Netscape 6+, Mozilla, Phoenix,
// Camino, Galeon, K-Meleon, AOL 7 for Mac OSX, and CompuServe 7.
// Spoof-proof for Safari.
var brGecko=(ua.indexOf('Gecko') != -1 && ua.indexOf('Safari') == -1) ? true:false;

// Netscape 4.x
var brNS4=(document.layers) ? true:false;

// Opera 6 or greater.
var brOP6=(ua.indexOf('Opera') != -1 && (parseInt(ua.split('Opera ')[1]) >= 6 || parseInt(ua.split('Opera/')[1]) >= 6)) ? true:false;

// Safari
var brSafari=(ua.indexOf('Safari') != -1) ? true:false;

Hope this helps!

04-11-2003, 09:07 PM
I have a client-sniffer for this kind of thing - http://www.brothercake.com/scripts/sniffer.php

Then what I do is have a file called "menu.js", and conditionalise another script include inside that:

var brStr = '';
if(ie5) { brStr = 'ie5'; }
else if(op7||ns6) { brStr = 'moz'; }
//.. and so on ... then
document.write('<script type="text/javascript" src="menu_'+brStr+'.js"></script>');

04-12-2003, 11:26 AM
Thanks all, I am a novice somewhat in this field, so it will take me some time to get this working.

Cheers for the replies... I'll keep y'all posted.