开发者

Javascript enable prompt [duplicate]

开发者 https://www.devze.com 2023-03-29 05:37 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: opposite of <noscript>
This question already has answers here: Closed 11 years ago.

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?


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

<body>
<script type="text/javascript">
    document.write("HELLO");
</script>
<noscript>Please Enable JavaScript</noscript>
</body>


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

精彩评论

暂无评论...
验证码 换一张
取 消