Solved

Don't read in IE

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can in rewrite this js anonymous function as a named function 26 33
asp Google Map 2 33
Copying table data to one another 15 31
Responsive Font Size 6 30
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

821 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