Question

Source Code:

if (navigator.userAgent.toLowerCase().indexOf('msie') != -1 && parseInt($.browser.version, 10)<7)

Edited - sorry, posted wrong code.

What's the correct formation of the above, to identfiy browsers less than ie9?

thanks

Edit -

Here's the reason for the code above:

if (navigator.userAgent.toLowerCase().indexOf('msie') != -1 ) {
                    hidden = document.createElement('<input type="hidden" name="' + atName + '" value="' + attrId + '"/>');
                } else {
                    hidden = document.createElement("input");

it's for the createElement issue in anything lower than IE9

Additionally, I would love to rewrite the entire function, but due to scope I am unable to rewrite the file until it's included in a project - so I need to rewrite this one line to work correctly.

Was it helpful?

Solution

AND is not a valid javascript keyword. VERSION neither seems to be declared anywhere. Also I would recommend you to never test against a specific navigator or version but test against whether the browser supports the functionality you want to use. A technique called feature detection. So for example if you want to use the HTML5's canvas element don't test if the browser is XXX and the version is YYY. Test if the browser supports the HTML canvas element. Modernizr is an excellent library for this job.


UPDATE:

And if you don't want to hear about good practices and still insist on this browser version detection:

if ($.browser.msie && parseInt($.browser.version, 10) < 9) {
    alert('Warning, you are running a crap of a browser. Please upgrade!');
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top