问题
I'm looking for something good-loking that I can paste on a page and be done with it.
The script should detect IE versions older than 9 and show a nice popup with links to different browsers or something like that. I could do it myself, but I'd rather not reinvent the wheel.
回答1:
When I first posted this answer, the modern.IE project were pushing the IE6 countdown initiative, part of which was the provision of a IE detection snippet and hosted image used to warn users that they're using an old browser.
I originally linked to http://www.ie6countdown.com/ which now redirects to an area on modern.IE which no longer provides the snippet and image. So, for prosperity and reference, here is the code they were sharing and the original banner image hosted on imgur:
<!--[if lt IE 7]>
<div style=' clear: both; height: 59px; padding:0 0 0 15px; position: relative;'>
<a href="http://www.microsoft.com/windows/internet-explorer/default.aspx?ocid=ie6_countdown_bannercode">
<img src="http://i.imgur.com/hNingci.jpg" border="0" height="42" width="820" alt="" />
</a>
</div>
<![endif]-->
If you want to change this to detect IE versions less than 9 just change the first bit of the code to this:
<!--[if lt IE 9]>
回答2:
I would probably use a comment hack with IE
conditional comments to do the version detection.
<!--[if lt IE 8 ]>
<script type='text/javascript'>
alert( 'Your IE is Old' );
// or set a flag or something
var oldIE = true;
</script>
<![endif]-->
It's technically not using javascript to do the detection and is rather using a feature inherent to IE but it should work more consistently than a complex javascript function.
回答3:
This one offers customizable browser versions, not just for IE but also for Firefox, Opera, Safari. http://browser-update.org/
回答4:
Recently I developed a free jQuery plugin that shows a well designed warning message to the visitor who's trying to view your site with an older version of Internet Explorer browser.
Site: http://nmsdvid.com/iealert/
来源:https://stackoverflow.com/questions/10212503/javascript-to-detect-an-old-internet-explorer-and-offer-to-download-newer-browse