Solved

conditional statement in html not working

Posted on 2013-06-19
10
155 Views
Last Modified: 2013-06-28
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
<!-- [if !IE]> -->
		This browser is not supported! Please use Internet Explorer.  
 <!-- [endif] -->

Open in new window

0
Comment
Question by:icecom4
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 33

Expert Comment

by:paulmacd
ID: 39260388
To begin with, it's not formatted properly.

<!--[if !IE]>
     This browser is not supported! Please use Internet Explorer.
<![endif]-->


Also, this:
http://stackoverflow.com/questions/13785587/if-ie-not-working
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39260415
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
0
 

Author Comment

by:icecom4
ID: 39260436
@paulmacd
if I use the exact code you provided, both IE and Mozilla are ignoring it.

by the way I am using IE10
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39260470
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.
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
ID: 39260488
<!--[if !IE]><!-->
      This browser is not supported! Please use Internet Explorer.
 <!--<![endif]-->

Cd&
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:icecom4
ID: 39260608
@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!
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39260709
You probably need to use javascript:

var isIE= (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) ? 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&
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39260728
For the server side in PHP:

(eregi("MSIE", getenv( "HTTP_USER_AGENT" ) )

for ASP:

InStr(1, Request.ServerVariables("HTTP_USER_AGENT"), "MSIE")


Cd&
0
 

Author Comment

by:icecom4
ID: 39260831
not sure why, but if I place this immediately after the header and nowhere else it works!

example...
<body style="background-color: #FFFFFF; background-image: url('')">
</body></html>

<!-- [if !IE]> -->
		This browser is not supported!&nbsp;&nbsp; Use the &quot;Internet Explorer&quot; 
		shortcut on your desktop to start NextGen.
 <!-- [endif] --> 

Open in new window


sigh...that was fun...and annoying
0
 

Author Closing Comment

by:icecom4
ID: 39285068
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.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now