View Full Version : Screen resolution detect - return different stylesheets
AdamC
11-18-2002, 01:20 PM
I need a script that will detect the screen resolution being used and return a different stylesheet accordingly.
Any help much appreciated.
Vladdy
11-18-2002, 01:34 PM
I would recommend using the size of the browser client window, not the screen resolution, for this. In any case, here is an outline of such script:
in the <head>:
function setStyleSheet()
{ width = getTheWidthThatMatters();
height = getTheHeightThatMatters();
if(width<800 && height<600)
{ document.writeln('your stylesheet link ');
return;
}
// more ifs as needed
}
setStyleSheet();
AdamC
11-18-2002, 01:36 PM
I've tried this but get a runtime error message indicating an expected ')' in the line beneath "Begin"
<SCRIPT LANGUAGE="JavaScript1.2">
<!-- Begin
if (screen.height >= 768 && screen.width >= 1024) {
document.write("<link rel="stylesheet" href="solution_styles.css" type="text/css">");
}
else {
if (screen.height == 600 && screen.width == 800) {
document.write("<link rel="stylesheet" href="solution_styles2.css" type="text/css">");
}
else {
document.write("<link rel="stylesheet" href="solution_styles.css" type="text/css">");
}
}
// End -->
</script>
Vladdy
11-18-2002, 01:40 PM
check your " :rolleyes:
and never trust IE "Scrpt Error" to give you the correct line number
AdamC
11-18-2002, 01:41 PM
yeah - just realised. A little embarressed. Thanks for your suggestion anyway.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.