Jump to content

HTML If/Else


The Little Guy

Recommended Posts

There are HTML conditional statements, I've generally seen them (and have used them) when loading browser-specific stylesheets. As far as I'm aware, they have nothing to do with JavaScript so you should get the same results with JS switched on or off.

 

Though, it triggers the thought - Surly it would be quicker to just switch JavaScript off in your browser and test it, rather than ask on a forum what might happen?!

Link to comment
Share on other sites

ha! your right, my instructor was just using them as comments, I thought they were actually doing something. my mistake.

 

<!-- [if!IE]>  Firefox and others will use outer object -->
1
<!--<![endif]-->
<!-- MSIE (Microsoft Internet Explorer) will use inner object -->
2
<!-- [if!IE]> close outer object -->
3
<!--<![endif]-->

 

Which by the way is not in any way related to html.

 

you can use java applets and add them to your HTML

Link to comment
Share on other sites

OK, I see they just use styles, and I guess that the styles don't show up when javascript is turned on.

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Hw1</title>
<style>
	noscript{
		width: 100%;
		display:block;
		position:absolute;
		bottom:0;
		top:0;
		background-color:#FFF;
	}
	body{
		padding:0;
		margin:0;
	}
</style>
</head>
<body>
<noscript>
<h1>Turn On your JavaScript</h1>
</noscript>
<div>
Congradulations! Your JavaScript Is Turned On!!!
</div>
</body>
</html>

Link to comment
Share on other sites

If you want something only to be visible when javascript is on, then in the html/css code, set the element's display property to none. Then, in the window.onload function, set the display property of that element to either block or inline. In this way, the element will never be made visible if the user has javascript off, and if they have it on, when the window is done loading, the element will be made visible.

Link to comment
Share on other sites

you can have a look on this as well:

 

<noscript>

<META HTTP-EQUIV="Refresh" CONTENT="3;URL=http://www.some.org/some.html">

<noscript>

 

You shouldn't do that. meta is not allowed inside noscript according to the DTD. Furthermore:

 

Note. Some user agents support the use of META to refresh the current page after a specified number of seconds' date=' with the option of replacing it by a different URI. Authors should not use this technique to forward users to different pages, as this makes the page inaccessible to some users. Instead, automatic page forwarding should be done using server-side redirects.[/quote']

 

Here is an excerpt from the XHTML 1.0 Strict DTD (HTML 4.01 looks almost the same):

<!ENTITY % misc.inline "ins | del | script">
<!ENTITY % misc "noscript | %misc.inline;">
<!ENTITY % heading "h1|h2|h3|h4|h5|h6">
<!ENTITY % lists "ul | ol | dl">
<!ENTITY % blocktext "pre | hr | blockquote | address">
<!ENTITY % block "p | %heading; | div | %lists; | %blocktext; | fieldset | table">
<!ENTITY % Block "(%block; | form | %misc;)*">
<!ELEMENT noscript %Block;>

 

(Oddly enough, this allows you to use script inside noscript and another noscript may appear inside the first noscript)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.