icecom4
asked on
conditional statement in html not working
I can't seem to figure out why this snippet of code is picky. When I place it in most places within an html page, it does not work. However I did get it to work in one seemingly random spot. Is there something that I should add before and after to allow me to place it anywhere and work?
The below code displays a message to non-IE users
The below code displays a message to non-IE users
<!-- [if !IE]> -->
This browser is not supported! Please use Internet Explorer.
<!-- [endif] -->
Only Internet Explorer support conditional comments, all other browser ignore such things. You will have to use javascript browser detection to inform the other browsers.
http://www.w3schools.com/js/js_window_navigator.asp
http://www.w3schools.com/js/js_window_navigator.asp
ASKER
@paulmacd
if I use the exact code you provided, both IE and Mozilla are ignoring it.
by the way I am using IE10
if I use the exact code you provided, both IE and Mozilla are ignoring it.
by the way I am using IE10
All browsers but IE ignore conditional comments, they treat them as just plain comments. And your statement [if !IE] tells IE to ignore it. You have to use a different method.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@COBOLdinosaur
Sorry, but your code always displays the statement in both browsers...shrug?
@ DaveBaldwin
Yes, this is what I want, a statement that IE will ignore and all other browsers show the statement!
Sorry, but your code always displays the statement in both browsers...shrug?
@ DaveBaldwin
Yes, this is what I want, a statement that IE will ignore and all other browsers show the statement!
You probably need to use javascript:
var isIE= (/MSIE (\d+\.\d+);/.test(navigato r.userAgen t)) ? true : false;
if (!isIE) document.write('You need to use Internet Explorer fot this page');
Or do it properly by detecting on the server and send a page with just the message instead of wasting bandwidth sending the whole page.
Cd&
var isIE= (/MSIE (\d+\.\d+);/.test(navigato
if (!isIE) document.write('You need to use Internet Explorer fot this page');
Or do it properly by detecting on the server and send a page with just the message instead of wasting bandwidth sending the whole page.
Cd&
For the server side in PHP:
(eregi("MSIE", getenv( "HTTP_USER_AGENT" ) )
for ASP:
InStr(1, Request.ServerVariables("H TTP_USER_A GENT"), "MSIE")
Cd&
(eregi("MSIE", getenv( "HTTP_USER_AGENT" ) )
for ASP:
InStr(1, Request.ServerVariables("H
Cd&
ASKER
not sure why, but if I place this immediately after the header and nowhere else it works!
example...
sigh...that was fun...and annoying
example...
<body style="background-color: #FFFFFF; background-image: url('')">
</body></html>
<!-- [if !IE]> -->
This browser is not supported! Use the "Internet Explorer"
shortcut on your desktop to start NextGen.
<!-- [endif] -->
sigh...that was fun...and annoying
ASKER
this is the right code, but requires spaces before the dashes. I was able to get it to work by placing in a specific place in html code. It is also unstable, and does not always work depending on network conditions for some reason.
I am abandoning this idea, will search for another way.
I am abandoning this idea, will search for another way.
<!--[if !IE]>
This browser is not supported! Please use Internet Explorer.
<![endif]-->
Also, this:
http://stackoverflow.com/questions/13785587/if-ie-not-working