<! - [If IE]> Doesn't work

<html> <head> <!-- [If IE]><script>alert('IE!')</script><![endif] --> </head> <body> <p> Hello World </p> </body> </html> 

Is there something wrong with this, or do I need to add a DOCtype / meta header to make it work?

+4
source share
2 answers

This is just to clarify (since nobody really has).

This is a space between <!-- and [If IE] , as well as a space after [endif] , which breaks your code. It does not exist in any of the answers that were before mine, so they work, and yours do not.

Bad:

 <!-- [If IE]> <![endif] --> 

Good:

 <!--[If IE]> <![endif]--> 

<!DOCTYPE html> is good practice, but not required for this.

+9
source

This should work fine:

 <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Untitled Document</title> <!--[if IE]><script src="global.js"></script><![endif]--> </head> <body> <p>Hello world</p> </body> </html> 
+2
source

Source: https://habr.com/ru/post/1433975/


All Articles