I have the following 2 statements, and would like to combine them into one statement: if(navigator.userAgent.indexOf("Firefox")!=-1){ var versionindex=navigator.userAgent.indexOf("Firefox")+8 if (parseInt(navigator.userAgent.charAt(versionindex))>=2) alert("You are using Firefox 2.x or above") } version=0 if (navigator.appVersion.indexOf("MSIE")!=-1){ temp=navigator.appVersion.split("MSIE") version=parseFloat(temp[1]) } if (version>=7) //NON IE browser will return 0 alert("You're using IE7+") Basically, what I would like this to do is the following: IF the browser is either Firefox 2 or higher, OR IE7 or higher, do NOTHING. Else, alert the user. Could anybody please help me? I've been trying for hours, and no luck Thank you!
You and your site would look less bad if you didn't. Why don't you explain why you think you need to exclude other browsers?
Hope this is what you are looking for version=0 if(navigator.userAgent.indexOf("Firefox")!=-1){ var versionindex=navigator.userAgent.indexOf("Firefox")+8 if (parseInt(navigator.userAgent.charAt(versionindex))>=2) alert("You are using Firefox 2.x or above") }else if (navigator.appVersion.indexOf("MSIE")!=-1){ temp=navigator.appVersion.split("MSIE") version=parseFloat(temp[1]) if (version>=7) //NON IE browser will return 0 alert("You're using IE7+") } Code (markup):
How about this. You recode your website and make it so it's compliant and nice with all browsers? People hate websites that only work with one, and I guarantee they will hate being alerted and excluded.
Hey, I'm a big fan of Object detection. But the OP's request was to combine the two statements into one. I think my above code does acheive that objective.
Um, ok. To all you people who think I should re-code my website: this is for a couple of specific pages on my companie's website that use 3D models that only work in those 2 browsers.
Hello, thank you so much for this. It is ALMOST what I'm looking for. But how do I do it "the other way around". If a visitor uses Firefox 2 OR IE7, don't alert. If they use anything else, alert. Again, as I mentioned in a seperate post, this is for a couple of pages of our website where we show specific 3D models that do not work properly in any other browser... Thank you!
Hi, I think this will work. Just comment out the other alerts and add another else. See if works for ya. version=0 if(navigator.userAgent.indexOf("Firefox")!=-1){ var versionindex=navigator.userAgent.indexOf("Firefox")+8 if (parseInt(navigator.userAgent.charAt(versionindex))>=2) //alert("You are using Firefox 2.x or above") }else if (navigator.appVersion.indexOf("MSIE")!=-1){ temp=navigator.appVersion.split("MSIE") version=parseFloat(temp[1]) if (version>=7) //NON IE browser will return 0 //alert("You're using IE7+") } else{ alert("You are using an incompatible browser") } Code (markup):
If by 'work' you mean slander the capabiliites of other browsers, then probably yes. else{ alert("I have decided that you are using an incompatible browser, despite not having perfomed any tests to establish its actual capabilities.") } Code (markup):