Solved

Don't read in IE

Posted on 2008-10-23
3
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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 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 embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

726 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