当JavaScript停用时,如何显示不同的内容? [英] How can I show different content when JavaScript is disabled?

查看:109
本文介绍了当JavaScript停用时,如何显示不同的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当JavaScript停用时,我需要显示完全不同的内容。我知道我可以使用< noscript> 标签...但是当JavaScript被禁用时,如何隐藏页面的其余部分?



感谢。

解决方案

这里是另一种解决方案:



在您的正常样式表下方有:

 < link rel =stylesheethref =jsdisabled.css /> 
< script type =text / javascript>
document.write('< link rel =stylesheethref =jsenabled.css/>');
< / script>

jsenabled.css会有:

  #content {display:block; } 

而jsdisabled.css会有:

  #content {display:none; } 

虽然下面的解决方案无效,

您可以放置​​一些风格标签隐藏其余内容



ie:

 < noscript> 
< style type =text / css>
#content {display:none; }
< / style>
没有js内容来这里。
< / noscript>

< div id =content>
的内容在这里。
< / div>

我喜欢使用这种方法,因为当javascript启用时,不会使页面闪烁。 p>

I need to show COMPLETELY different content when JavaScript is disabled. I know I can use <noscript> tag... but how can I hide the rest of the page when JavaScript is disabled?

Thanks.

解决方案

here is another solution:

inside your head below your normal stylesheet have:

<link rel="stylesheet" href="jsdisabled.css" />
<script type="text/javascript">
    document.write('<link rel="stylesheet" href="jsenabled.css" />');
</script>

that jsenabled.css would have:

#content { display:block; }

while jsdisabled.css would have:

#content { display:none; }

although the solution below works it does not validate

inside your noscript tag you can put some style tag that hides the rest of your content

ie:

<noscript>
    <style type="text/css">
        #content { display:none; }
    </style>
    no js content goes here.
</noscript>

<div id="content">
    content here.
</div>

I like using this method because it doesn't make the page flash when javascript is enabled.

这篇关于当JavaScript停用时,如何显示不同的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆