P
piraticman
I have this script which will load a seperate stylesheet if the user is
browsing in a resolution with height over 980px. This will stop the
page from looking too small on higher resolutions, it works fine on a
browser that supports the script, it works fine on a computer without
javascript (no script just ingores it and runs the default CSS file)
but in a browser WITH javascript that does not support this action no
CSS file is loaded at all.
My code is below.
<head>
<link id="style" rel="stylesheet" type="text/css" />
<noscript>
<link href="style.css" rel="stylesheet" type="text/css" />
</noscript>
<script type="text/javascript">
//<![CDATA[
function sniffer() {
var screen_height = screen.height;
var screen_width = screen.width;
if (screen_height >= 960) {
document.getElementById("style").href="style2.css";
}
else {
document.getElementById("style").href="style.css";
}
}
window.onload=sniffer;
//]]>
</script>
If I change the line
<link id="style" rel="stylesheet" type="text/css" />
to
<link href="style.css" rel="stylesheet" type="text/css" />
it will load the style.css as the stylesheet, but this disables the
javascript function.
So the question is: Is there a way to set the default stylesheet as
style.css but have the javascript override the default stylesheet,
because if there is no default stylesheet,a browser that does not
support the javascript function will not load a stylesheet. The no
script loads a default css file for users with no javascript.
Hope this makes sense.
Thanks in advance
Daniel
browsing in a resolution with height over 980px. This will stop the
page from looking too small on higher resolutions, it works fine on a
browser that supports the script, it works fine on a computer without
javascript (no script just ingores it and runs the default CSS file)
but in a browser WITH javascript that does not support this action no
CSS file is loaded at all.
My code is below.
<head>
<link id="style" rel="stylesheet" type="text/css" />
<noscript>
<link href="style.css" rel="stylesheet" type="text/css" />
</noscript>
<script type="text/javascript">
//<![CDATA[
function sniffer() {
var screen_height = screen.height;
var screen_width = screen.width;
if (screen_height >= 960) {
document.getElementById("style").href="style2.css";
}
else {
document.getElementById("style").href="style.css";
}
}
window.onload=sniffer;
//]]>
</script>
If I change the line
<link id="style" rel="stylesheet" type="text/css" />
to
<link href="style.css" rel="stylesheet" type="text/css" />
it will load the style.css as the stylesheet, but this disables the
javascript function.
So the question is: Is there a way to set the default stylesheet as
style.css but have the javascript override the default stylesheet,
because if there is no default stylesheet,a browser that does not
support the javascript function will not load a stylesheet. The no
script loads a default css file for users with no javascript.
Hope this makes sense.
Thanks in advance
Daniel