tags:

views:

937

answers:

4

Hi,

Let's say, I have html code like this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
This is content.
</body>
</html>

And I want to add <noscript> tag there. Which means, if the javascript disabled. Will show as blank page.

And only when enable the javascript, it will show "This is content text".

Please give me some example to achieve. Thanks.

+1  A: 

It's a little odd.

You don't even need a 'noscript' for this. You can just have a blank first page, who's only content is a javascript of the form:

document.location = '/realpage.htm';

And then call that OnLoad, with jQuery, or whatever. This will mean if the client doesn't have scripting, they don't go anywhere, hence the page remains blank.

-- Edit:

Example, as requested:

<html>
<body onload="document.location = 'realpage.html';">

</body>
</html>
Noon Silk
hi silky,I want to try your way too. But since of the lack of knowledge. I don't know how to do. Can you write the sample code for me to test ? Thanks.
Done.
Noon Silk
Thanks for your response silky. Got it.
A: 

The noscript tag works the other way around. To make the content visible when script is enabled, put it in an element that is hidden, and show it using script:

<div id="hasScript" style="display:none">
This is content
</div>
<script>document.getElementById('hasScript').style.display='';</script>
Guffa
+3  A: 

Wrap all you contents inside a main div with display none and in the onload function change the display to block.

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div id="divMain" style="display: none">
This is content.
</div>
<noscript>
js not enabled
</noscript>
<script>
document.getElementById ( "divMain" ).style.display = "block";
</script>
</body>

</html>
rahul
thanks it's working. Just want to know another question that, even if we add noscript tag, can they still view the source code ?
Yes of course, noscript has nothing to do with HTML generation.
rahul
ah okie. Thanks for your quick and fast response.
A: 

You could do something like

<body id="thebody">
  this is content.
  <script>
    document.getElementById('thebody').innerHTML = "<p>content when JS is enabled!";
  </script>
</body>
Alex Martelli