0

Possible Duplicate:
opposite of <noscript>

I have a static html page as following:

<head>
<noscript>Please Enable JavaScript</noscript>
</head>

<body>
<br />
HELLO
</body>

This will prompt the user to enable Javascript. But "HELLO" is getting displayed no matter whether JavaScript is disabled or enabled. I want "HELLO" to get displayed if JavaScript is enabled and want the prompt to appear and "HELLO" to hide when JavaScript is disabled. It will be better if it is a cross-browser solution. How can I do this?

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Alfred
  • 20,303
  • 60
  • 160
  • 239
  • 4
    See http://stackoverflow.com/questions/2297643/opposite-of-noscript. By the way, you shouldn't display text inside `` tag. Move the ` – JJJ Aug 20 '11 at 11:25

2 Answers2

0

You could make Hello a javascript, like this...

<body>
<script type="text/javascript">
    document.write("HELLO");
</script>
<noscript>Please Enable JavaScript</noscript>
</body>
fireshadow52
  • 5,888
  • 2
  • 29
  • 45
0

Your code currently has HELLO displaying in plain HTML, regardless if JavaScript is enabled or not. And the <noscript> tag belongs within the <body>.

The example below will write HELLO if the user has JavaScript enabled. But if JavaScript is disabled, Please Enable JavaScript will be shown instead.

<head>
</head>

<body>
    <script type="text/javascript">
        document.write("HELLO");
    </script>
    <noscript>
        Please Enable JavaScript
    </noscript>
</body>
Chris McFarland
  • 5,932
  • 5
  • 46
  • 62