Help with if statment

var safari = navigator.appVersion.indexOf("Safari");
var chrome = navigator.appVersion.indexOf("Chrome")
if (safari) {
    alert("Safari");
}
else if (chrome) {
    alert("Chrome")
}
else {
    alert("Not Safari or Chrome");
}

i have this code but chrome alerts as safari because it has safari in it’s appVersion string. so i want (in the fist if condition) for it to read “if safari and if not chrome then…”

i can’t think how to do it. Help!

navigator.userAgent has all that information. Check what each one returns to work out the logic of it.

You should be aware that browser detection (what you’re doing) is a very bad idea in most cases. Why do you need to do it?

i realise it’s a crap idea but i need to do it because all the text in safari appears 5 pixels up from where it should be.

Then you need to post your problem in the CSS forum. This is a really really messy way to fix it. I cannot stress enough that this is the wrong way to go about it. :slight_smile:

kk i’ll see if there is a css fix then