Solved

Don't read in IE

Posted on 2008-10-23
3
148 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
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 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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 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

19 Experts available now in Live!

Get 1:1 Help Now