BrotherArnold
Technical User
Hi,
The following test code is meant to select a css depending on screen width but it doesn't work - it writes the LINK tag to a new document. However, if I delete the function line and remove the onload bit, it works. Why is that? If I'm going to be adding more functions can I get by with this code set within the script tag but outside a function.If not what do I need to do to get this to work inside a function. As I'm sure you can gather I'm new to Javascript so any help would be much appreciated.
<HTML><HEAD><TITLE>test</TITLE>
<SCRIPT LANGUAGE=JavaScript>
function init()
{
if (screen.Width < 801)
document.write('<link rel="stylesheet" type="text/css" href="lowres.css" / >\n')
else
document.write('<link rel="stylesheet" type="text/css" href="hires.css" / >\n')
}
</SCRIPT>
</head>
<body onload="init();"><p>hi there, how's it going?</body>
</html>
Cheers
Brother Arnold
The following test code is meant to select a css depending on screen width but it doesn't work - it writes the LINK tag to a new document. However, if I delete the function line and remove the onload bit, it works. Why is that? If I'm going to be adding more functions can I get by with this code set within the script tag but outside a function.If not what do I need to do to get this to work inside a function. As I'm sure you can gather I'm new to Javascript so any help would be much appreciated.
<HTML><HEAD><TITLE>test</TITLE>
<SCRIPT LANGUAGE=JavaScript>
function init()
{
if (screen.Width < 801)
document.write('<link rel="stylesheet" type="text/css" href="lowres.css" / >\n')
else
document.write('<link rel="stylesheet" type="text/css" href="hires.css" / >\n')
}
</SCRIPT>
</head>
<body onload="init();"><p>hi there, how's it going?</body>
</html>
Cheers
Brother Arnold