In order to detect IE most Javascript libaries do all sort of tricks.
- jQuery seem to add a temporary object into your pages's DOM to detect some features,
- YUI2 does regex on the user agent in its
YAHOO.env.ua = function()
(fileyahoo.js
)
After reading this answer it came in my mind that it's true, in order to detect simply IE in Javascript we could simply add to our pages:
<!--[if IE]><script type="text/javascript">window['isIE'] = true;</script><![endif]-->
<script type="text/javascript" src="all-your-other-scripts-here.js"></script>
Now the window.isIE
variable is set for all our Javascript code, by simply doing:
if(window.isIE)
...
Beside the fact that this might result in being a pain because it has to be added in all pages, are there any issues/considerations I might be unaware of?
FYI: I know it's better to use object detection rather than browser detection, but there are cases where you still have to use browser detection.