Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

html - noscript alternative in XHTML?

In HTML I could do:

<noscript><link href="css/stylenojs.css" rel="stylesheet" type="text/css" /></noscript>

Is there some compliant way to do so in XHTML Transitional or Strict documents?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The example you give is invalid in HTML as well as XHTML. No current recommendation provides a way to include a stylesheet unless scripting is enabled.

In general, you should avoid <noscript>. Start with something that works, and then build on it.

In this case, you could write your stylesheet for non-JS clients, then:

<body>
<script type="text/javascript">document.body.className += ' js';</script>

… and include additional rule-sets specific to JS being enabled with:

body.js foo {
}

Alternatively, you could do something like:

<link href="css/stylenojs.css" rel="stylesheet" type="text/css" id="nojscss" />

and

var nojscss = document.getElementById('nojscss');
nojscss.parentNode.removeChild(nojscss);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...