admin管理员组文章数量:1325594
If no JavaScript is enabled, I want my body to have overflow:hidden
(no scrollbars).
How can I solve this? Is it possible to use a noscript tag inside of <head> and set specific styles inside of it?
If no JavaScript is enabled, I want my body to have overflow:hidden
(no scrollbars).
How can I solve this? Is it possible to use a noscript tag inside of <head> and set specific styles inside of it?
Share Improve this question edited Oct 2, 2011 at 18:17 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Nov 23, 2010 at 9:53 mattmatt 44.4k107 gold badges268 silver badges402 bronze badges4 Answers
Reset to default 5If you mean the <body>
of the HTML document, I'd build the HTML as it should be for the users with JS disabled. For example in the CSS file have body { overflow:hidden }
and then use JavaScript to set the page as it should be for users with JavaScript enabled (i.e. remove the overflow:hidden
with JavaScript).
I'm pretty sure
<noscript>
<style type="text/css">
body {
overflow:hidden;
}
</style>
</noscript>
in your <head>
would do the job.
But as stated in the other post, it may be better to use CSS for this purpose, and enable overflow for browsers with JavaScript.
It's not valid using the <noscript>
tag inside the head section (it is allowed only inside <body
>), so you could use this workaround instead (an HTML5 example)
<!doctype html>
<html lang="en">
<head>
<script>document.documentElement.className = 'js';</script>
<style>
body { overflow: hidden; }
html.js body { overflow: auto; }
</style>
</head>
This is probably a super overkill, but just for general knowledge:
Modernizr uses a mechanism where it suggest you put the no-js
class on your html tag. If modernizr runs, it removes the no-js
class. Using modernizr would be an overkill, but you could do this yourself. In your css you would have:
html.no-js body {
overflow:hidden;
}
本文标签: javascriptBody styling for a noscript tagStack Overflow
版权声明:本文标题:javascript - Body styling for a noscript tag? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742190409a2430106.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论