document.write() and alert() in this case are basically interchangeable, ex:
Code:
<script type="text/javascript">
/*@cc_on @*/
/*@if(@_jscript_version >= 5)
document.write('Internet Explorer ' + navigator.userAgent.replace(/^.*MSIE[^\d]*([\d\.]*).*$/, '$1'));
@end @*/
</script>
The only difference being that when using document.write(), you must place the script in the flow of the page where you want the written text to appear.
Another refinement, if you only want sub version numbers (.0 in the case of IE 7) displayed for those IE browsers that actually have them (IE has had no sub version numbers since IE 6) use it like so:
Code:
<script type="text/javascript">
/*@cc_on @*/
/*@if(@_jscript_version >= 5)
document.write('Internet Explorer ' + (navigator.userAgent.replace(/^.*MSIE[^\d]*([\d\.]*).*$/, '$1') - 0));
@end @*/
</script>
This way it will strip the sub version (the decimal point and the 0 following it) unless there is a number there after the decimal point that is not 0.
Bookmarks