问题
I wonder if it's possible to show a warning or open a pop-up, which would say update your IE to latest version or use Firefox / Chrome / Safari instead, when browser is Internet Explorer IE8 or older...
I guess I should use that code below inside the tags...
<!--[if lt IE 9]>
...i should use code here...
<![endif]-->
Is it smart to deceted browser with jQuery and loading jQuery lib? Or is it better to just use regular javascript in order to avoid additional issues with very old browsers?
回答1:
You have two options:
Parse the the
User-Agent String
// Returns the version of Internet Explorer or a -1 // (indicating the use of another browser). function getInternetExplorerVersion() { var rv = -1; // Return value assumes failure. if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) { rv = parseFloat( RegExp.$1 ); } } return rv; } function checkVersion() { var msg = "You're not using Internet Explorer."; var ver = getInternetExplorerVersion(); if ( ver > -1 ) { if ( ver >= 9.0 ) { msg = "You're using a recent copy of Internet Explorer." } else { msg = "You should upgrade your copy of Internet Explorer."; } } alert(msg); }
Using Conditional Comments:
<!--[if gte IE 9]> <p>You're using a recent version of Internet Explorer.</p> <![endif]--> <!--[if lt IE 8]> <p>Hm. You should upgrade your copy of Internet Explorer.</p> <![endif]--> <![if !IE]> <p>You're not using Internet Explorer.</p> <![endif]>
Reference: Detecting Windows Internet Explorer More Effectively
回答2:
You could use something like this
The ie6-upgrade-warning is a little script (7.9kb) that displays a warning message politely informing the user to upgrade the browser to a newer version (links to newest IE, Firefox, Opera, Safari, Chrome are provided).
The webpage is still visible behind a transparent background, but access to it is prevented. The idea is to force users to upgrade from IE6 and avoid the website from a bad reputation that website is not rendering correctly in IE6.
The script is completely translatable in any language, very easy to set-up (one line of code in webpage and one parametter configuration).
Although was created to be used with IE6 users, using the correct parameters you can use it for your scenario.
回答3:
<script> var ISOLDIE = false; </script>
<!--[if lt IE 9]>
<script> var ISOLDIE = true; </script>
<![endif]-->
Then later on, where ever you want to draw the line for supporting older versions of IE in your code:
<script>
if(ISOLDIE) {
alert("Your browser currently does not support this feature. Please upgrade.");
window.location = 'http://google.com/chrome';
}
</script>
It's typically not a good idea to completely remove IE8 support, which is why I think the above solution is a good compromise, because you can add it to components of your website/web application which simply cannot be made to support IE8, but then you could (possibly) still support IE8 in other areas of your website.
回答4:
There is this dutch website forcing IE6 and lower users to upgrade their browser, a little adjustment to the "If IE" code you can block from whatever version you like.
http://wijstoppenook.nl/nl/
Scroll down to step 4 and click download or "voorbeeld" for a demo, the first one is a top banner, the second one completely blocks the page.
The only downside, its all in dutch so you'd have to make up your own message.
回答5:
Conditional comments are no longer supported in IE 10. WTF! Link
回答6:
On your site add your code to index.html or index.php
Its working also joomla and wordpress.
<!--[if IE 5]>
<script language="Javascript">
<!--
alert ("It looks like you aren't using Internet Explorer 7. To see our site correctly, please update.")
//-->
</script>
<![endif]-->
<!--[if IE 5.0]>
!--
alert ("It looks like you aren't using Internet Explorer 7. To see our site correctly, please update.")
//-->
</script>
<![endif]-->
<!--[if IE 5.5]>
!--
alert ("It looks like you aren't using Internet Explorer 7. To see our site correctly, please update.")
//-->
</script>
<![endif]-->
<!--[if IE 6]>
!--
alert ("It looks like you aren't using Internet Explorer 7. To see our site correctly, please update.")
//-->
</script>
<![endif]-->
<!--[if IE 7]>
!--
alert ("It looks like you aren't using Internet Explorer 7. To see our site correctly, please update.")
//-->
</script>
<![endif]-->
<!--[if IE 8]>
!--
alert ("It looks like you aren't using Internet Explorer 8. To see our site correctly, please update.")
//-->
</script>
<![endif]-->
回答7:
There are many ways, but this is by far the most elegant: http://outdatedbrowser.com/en/how
来源:https://stackoverflow.com/questions/10044855/force-browser-update-if-ie8-or-older