Ninjakreborn Posted October 18, 2007 Share Posted October 18, 2007 if (the browser is ie6 OR LESS) { do this }else { do this } How do I do something like that in javascript. I need to figure out how to detect if it's internet explore 6 or below do something, else do something else. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted October 18, 2007 Share Posted October 18, 2007 I can't give you a sure fire way to do so but here is the general method. First, beware of any method that tells you to use the userAgent string. Checking the userAgent string is often the quickest and easiest method but it is also unreliable since they can be faked. The more proper method is to find a global variable or property that is specific to the browser in question and check for it's existence. For example, IE has a global window.event object used for event-handling and they also have a document.all array. I'm not sure when window.event was introduced, but for the sake of argument let's say it was at version 6. This means if you wanted to check for IE 5.5 or lower you could do something like: if(document.all !== undefined){ // We have an IE browser if(window.event == undefined){ // IE 5.5 or lower } } Again, I'm not saying the above code works or that those are properties you should be using. I'm saying that's the general method for truly detecting which browser the user is using. Using that knowledge and some google searching should land you with something you can use. Quote Link to comment Share on other sites More sharing options...
nogray Posted October 19, 2007 Share Posted October 19, 2007 You can use conditional comments, something like this <script language="javascript">var isIE6 = false;</script> <!--[if lte IE 6]> <script language="javascript">var isIE6 = true;</script> <![endif]--> <script language="javascript"> alert(isIE6); </script> Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted October 20, 2007 Share Posted October 20, 2007 you can also insert css, javacript, and HTML in html using: <!--[if lt IE 7]> <style ...> <script ...> <etc ...> <![endif]--> basically, it says "if you're IE version 7 or better, do this" -- and it doesn't affect other browsers. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.