2

我应该如何为未启用 JavaScript 的浏览器隐藏 HTML?我正在考虑类似以下的内容,但它不适用于我的 FF 浏览器,甚至无法验证。有什么想法吗?谢谢

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <body class="wrap">
        <noscript>
            <h1>JavaScript is turned off in your web browser.<br />Turn it on to use this site, then refresh the page.</h1>
            <style type="text/css">
                body { display:none; }
                noscript { display:block !important; }
            </style>
        </noscript>
        HTML for JavaScript only browsers goes here...
    </body>
</html>
4

1 回答 1

3

应该是这样的

<body class="wrap">

    <noscript>

        <h1>JavaScript is turned off O_o</h1>

        <style type="text/css">

            .onlyscript { display:none; }

        </style>

    </noscript>

    <div class="onlyscript">HTML for JavaScript only browsers goes here...</div>

</body>

因为这个

        <style type="text/css">
            body { display:none; }
            noscript { display:block !important; }
        </style>

真是令人困惑的构造和不合理的“!重要;” 采用。这可能会导致将来出现问题。最好是简单而不是制作聪明的错误农场:)

于 2012-11-07T02:32:09.050 回答