?
Solved

IF ELSE STATEMENT

Posted on 2006-04-18
7
Medium Priority
?
4,304 Views
Last Modified: 2009-03-11
Hi

I have the following code (which I am assuming is JavaScript) in my html header

        <!--[if IE]>
            <link rel="stylesheet" href="css/stylesheet1.css" type="text/css" />
        <![endif]-->

This uses the style sheet stylesheet1 if internet explorer is detected.  Is it possible to somehow convert this small script into an if else statement?  So if it is ie use stylesheet1 else use stylesheet2?

Thanks
0
Comment
Question by:narmi2
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 9

Assisted Solution

by:smaccari
smaccari earned 400 total points
ID: 16482689
This code is not Javascript.
It's certainly a server side code, as this code is in HTML comments <!-- --> and thus not parsed by the browser.
0
 
LVL 6

Expert Comment

by:nabsol
ID: 16482842
Hi

This is how you can do your job in javascript

<head>
<script language="JavaScript"><!--
browser_version= parseInt(navigator.appVersion);
browser_type = navigator.appName;
if (browser_type == "Microsoft Internet Explorer" && (browser_version >= 4)) {
document.write("<link rel='stylesheet' href='css/stylesheet1.css' type='text/css' />");
}
else{
document.write("<link rel='stylesheet' href='css/stylesheet1.css' type='text/css' />");
}
// --></script>
</head>

By Nab
0
 
LVL 1

Author Comment

by:narmi2
ID: 16482846
Do you know anything else about that code?

for example can i use an "else" in there? or a <> or ! e.g.

        <!--[if IE]>
            <link rel="stylesheet" href="css/stylesheet1.css" type="text/css" />
        <![endif]-->
        <!--[if NOT IE]>
            <link rel="stylesheet" href="css/stylesheet2.css" type="text/css" />
        <![endif]-->

or
        <!--[if IE]>
            <link rel="stylesheet" href="css/stylesheet1.css" type="text/css" />
        <![endif]-->
        <!--[if <> IE]>
            <link rel="stylesheet" href="css/stylesheet2.css" type="text/css" />
        <![endif]-->

or
        <!--[if IE]>
            <link rel="stylesheet" href="css/stylesheet1.css" type="text/css" />
        <![endif]-->
        <!--[if ! IE]>
            <link rel="stylesheet" href="css/stylesheet2.css" type="text/css" />
        <![endif]-->

will any of these work?

If this is the wrong forum for this, where do you think I should ask this question?

Thanks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 16

Accepted Solution

by:
sam85281 earned 1600 total points
ID: 16482853
There is no ELSE for that, instead of using else you would just use multiple if/endif.

<!--[if IE]>
<link rel="stylesheet" href="css/stylesheet1.css" type="text/css" />
<![endif]-->
<!--[if !IE]>
<link rel="stylesheet" href="css/stylesheet2.css" type="text/css" />
<![endif]-->

Note the (!) before IE in the second one.

-Sam
0
 
LVL 9

Expert Comment

by:smaccari
ID: 16482875
Look at Nabsol solution, it's full JS and should work for you.
I do not know about your syntax though, never seen this ;)
0
 
LVL 1

Author Comment

by:narmi2
ID: 16483151
ok thanks

so what is this code called?

and does it have further syntax?

<!--[if IE]>
<![endif]-->
0
 
LVL 16

Assisted Solution

by:sam85281
sam85281 earned 1600 total points
ID: 16483563
They're called conditional comments.

Not much else to them you can use (!)Not equal to / (g)Greater than / (gte)Greaterthan-equal to / (l)Less than / (lte)Lessthan/eq to and you can designate version number.

Examples:
<!--[if g IE5]>
<![endif]-->

<!--[if lte IE6]>
<![endif]-->

etc...

-Sam
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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…
Suggested Courses

864 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