Solved

Don't read in IE

Posted on 2008-10-23
3
149 Views
Last Modified: 2010-04-09
I have some javascript code that causes an error in IE.  I know how to add code that is only read in IE, but is there a way have add that is only read if you are NOT in IE?

I tried this but it didn't work.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 

	<link href='http://cp.com/' rel='home' title='CP'/>

	<meta content='index,follow' name='robots'/>

	<meta name="keywords" content="ph" />

	<meta name="description" content="This is what will show up in search engine results as the description of the site" />

	<meta name="author" content="CP" />

<!--[if IE]>	

		<script src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.js" type="text/javascript" charset="utf-8"></script>

	<script src="/assets/scripts/jquerycssmenu.js" type="text/javascript" charset="utf-8"></script>

	<script src="/assets/scripts/init.js" type="text/javascript" charset="utf-8"></script>

	<script src="/assets/scripts/jquery.preload-min.js" type="text/javascript" charset="utf-8"></script>

	<script type="text/javascript" src="/assets/scripts/jquery.pngFix.js"></script> 
 

	<script type="text/javascript"> 

	    $(document).ready(function(){ 

	        $(document).pngFix(); 

	    }); 

	</script>	

<![endif]-->
 

	<link rel="stylesheet" href="/assets/css/main-styles.css" type="text/css" media="screen" />

	<link rel="stylesheet" href="/assets/css/print-styles.css" type="text/css" media="print" />

	

<!--[if IE]><link rel="stylesheet" href="/assets/css/ie-style.css" media="screen" type="text/css" /><![endif]-->

	

<!--[if IE 6]><link rel="stylesheet" href="/assets/css/ie6-style.css" media="screen" type="text/css" /><![endif]-->
 

	<!-- Analytics -->

Open in new window

0
Comment
Question by:walker6o9
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
bluV11t earned 500 total points
ID: 22789227
Hi!
The conditional comment (like <!--[if IE]> ) only applies to IE.

"IE-based browsers like Maxthon and Avant handle them like Internet Explorer does while browsers using other layout engines see them simply as regular comments. Internet Explorer on the Mac uses a different layout engine and doesn't support conditional comments."
http://www.javascriptkit.com/dhtmltutors/csshacks.shtml
http://www.quirksmode.org/css/condcom.html

I think you need to check browser with javascript and output accordingly
http://www.quirksmode.org/js/detect.html
0
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 22791604
what you do is simply choose the IE conditional test at the beginning, and if it is not IE, you run the rest of the code for all other browsers --

if IE -- do this ...
else .... do this ....

Remember, you will need different code for IE6 than IE7 in many cases.  IE6 is the least compliant, so do --

If IE6 then do this
else if IE7 do that
else do the rest.
0
 
LVL 7

Expert Comment

by:bluV11t
ID: 22794717
The problem with your solution scratcyboy is that other browsers still treats conditional comments as regular comments.

<!--[if !IE]> and <!--[if IE]>  <![else]>  is therefore pointless IMO.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

930 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

12 Experts available now in Live!

Get 1:1 Help Now