Detect Internet Explorer and display a message - javascript

I have been looking around and cannot find what I am looking for
I want to display a warning to IE users that my website does not support IE nor will it ever try to and that you should get a better browser.
How you detect IE is really all I need but it would be nice if someone told me how to trigger a lightbox on the page but I can do that myself if you don't include it
Thank's for the help!

Conditional HTML comments will work for detecting IE9 or less. From the HTML5 Boilerplate, which I highly suggest you use:
<!--[if lt IE 7]>
<p class="chromeframe">You are using an <strong>outdated</strong> browser. Please upgrade your browser or activate Google Chrome Frame to improve your experience.</p>
<![endif]-->

Try this
if ($.browser.msie) {
// you are using IE
}
More detail : jquery.browser

navigator object has all details related to browser and platform details of clients machine.
navigator.userAgent gives browser related details.
JS snippet:
<script>
var x = navigator.userAgent;
alert(' browser details ' + x);
</script>
Below link talks at length about it in detail :
http://www.javascriptkit.com/javatutors/navigator.shtml

Paste the code after tag:
<!--[if lt IE 8]>
<p class="browserupgrade">Vous utilisez un <strong>ancien navigateur</strong>. Mettez votre navigateur à jour dès aujourd'hui !</p>
<![endif]-->
PS: edit the content as you need. I translate it into French for my own use.

Related

Prevent using IE8 with JAVASCRIPT

Is there a way in JAVASCRIPT (not jquery) to stop navigating a webpage in IE8 ?
( if i use jquery, a error appears : SCRIPT5009: jquery is not defined.).
In a company is still using IE8, They want to left behind little by little, so they need to send an ALERT when the user start navigating an specific webpage.
Note: Works perfectly in IE9 and Chrome
Regards
You can put scripts inside tags like this. These tags say run these scripts on versions of Internet Explorer that are below 9. So, you could write a script that posts a notice on your page about using outdated browsers.
<head>
<!--[if lt IE 9]>
<script src="outdated-browser-notification.js"></script>
<![endif]-->
</head>

Display div only in IE

I'm making a website at the moment and for some reason the z-index of a see through overlay is not working in internet explorer (it works in everything else), therefore I want to display a warning message that the website does not support internet explorer, how can I make a div with the class "Warning" show up only in internet explorer?
I am happy to this via any method (HTML, CSS, Jquery etc) as long as it either resolves the z-index issue or makes the warning div show.
Update: I had a friend of mine test my website and the conditional comments don't work in IE11, I want the div to be displayed in all versions of IE.
You can use a conditional statement to show the div:
<!--[if IE]>
<div class="warning">...</div>
<![endif]-->
This will work for all versions of IE, if you want to target specific versions, see here for more info.
EDIT: As GSerg has pointed out, this will only work for < IE11. For later versions of IE, you may have to rely on some JS like in this Q&A: Browser detection in JavaScript?
Html5 Boilerplate recommends this solution (checkout this link for more details):
<!--[if lt IE 8]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please upgrade your browser to improve your experience.</p>
<![endif]-->
Wrap your html in a conditional like so:
<!--[if lt IE 7]>[html here]<![endif]-->
the lt means 'less than'. You can target various version of IE by using lt, gt (greater than), lte (less than or equal to) and gte (greater than or equal to).

How to display a message when IE browser is opening?

I have a question and maybe it is duplicate in this site but i can't find it!
I want to display this message
"Please open this website in firefox and you can download Mozilla Firefox from here"
when users open my web in IE.
How do it?
Thanks in advance.
you can use a conditional check
<!--[if IE]>
please open this web in firefox and you can download Mozilla Firefox from <a href='here'>here</a>
<![endif]-->
or you could try adding a js/programming check
If you prefer Javascript, you can check the userAgent.
if (navigator.userAgent.indexOf('MSIE')>0) {
document.write('do something');
};
MSIE is the indicator for Microsoft Internet Explorer

Javascript not working on specific versions of IE

I've a rare issue with IE. I'm trying to create a page that launches this script when IE version is lower or equal than IE 8 (just a simple alert and a location). When I try to debug this html on IETester the alert only shows up on IE 5.5 and IE 6 but neither in 7 nor 8.
What am I doing wrong?
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<!--[if lte IE 8]>
<script type="text/javascript">
alert('Para poder usar Consumedia necesita tener instalada una version de Internet Explorer 9 o superior');
window.location = "http://www.google.com";
</script>
<![endif]-->
</head>
<body>
</body>
</html>
This is showing me the alert with native IE7.
It seems IETester might have a bug regarding conditional comments. See How do I make IE9 emulate IE7? for an alternative to IETester.
#Pekka has already commented on this matter a couple of times:
When multiple instances of Internet Explorer are installed (or active) on the same system, conditional comments will be resolved against the highest IE version available on the system
EDIT: Doesn't really add much, but I've got only IE7 installed, and it also shows the alert with IETester for IE <= 7.
Sory for my first answer, a don't realize the real problem.
Try to change the if statement:
<!--[if lt IE 9]>
//Fires for IE8 and above
<![endif]-->
See the examples here:
http://css-tricks.com/how-to-create-an-ie-only-stylesheet/

How do I verifying if site has javascript enabled and if user's browser is IE 8

How do I verify if a site has Javascript enabled and if user's browser is IE 8?
Use conditional comments and some javascript code (it will work only if it's enabled, right? :))
<!--[if IE 8]>
<script type="text/javascript"> /*do something in JS - it's enabled!*/ </script>
<[endif]-->
Or you may want to look at conditional compilation in JS
If for whatever reason you need to know that you are dealing with IE8,
you have to watch for the IE9 preview, which smells like IE8,
but has some new objects:
<!--[if IE 8]>
<script type="text/javascript">
if(document.addEventListener) alert('IE9');
if(document.documentMode) alert('IE8'+ running as '+document.documentMode);
</script>
<[endif]-->

Categories

Resources