Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with DTD

Status
Not open for further replies.

MattoThePotatto

Programmer
Jun 25, 2008
11
NZ
Hey, I made a script for the page to adjust for different resolutions.. Works fine.. until I declair a DOCTYPE..

Here's the script..

var w = window.screen.width;
if(w >= 1280)
{
document.write('<link rel="stylesheet" type="text/css" href="css/layout1280.css" media="screen" />');
document.write('<link rel="stylesheet" type="text/css" href="css/playout1280.css" media="print" />');
}
if(w >= 1024 && w < 1280)
{
document.write('<link rel="stylesheet" type="text/css" href="css/layout1024.css" media="screen" />');
document.write('<link rel="stylesheet" type="text/css" href="css/playout1024.css" media="print" />');
}
if(w >= 800 && w < 1024)
{
document.write('<link rel="stylesheet" type="text/css" href="css/layout800.css" media="screen" />');
document.write('<link rel="stylesheet" type="text/css" href="css/playout800.css" media="print" />');
}


Which DOCTYPE can I use, or what can I do to the script to stop this problem?
Thanks, ^^
 
I've tried a few other ways to execute the same script..
Same result...
Works fine until I put a doctype in...

------
HTML
Code:
<link rel="stylesheet" type="text/css" media="screen" />
<link rel="stylesheet" type="text/css" media="print" />

And the Javascript
Code:
var w = window.screen.width;
var s = document.getElementsByTagName("link")[0];
var p = document.getElementsByTagName("link")[1];
s.href = (w>=1280)?"css/layout1280.css":(w>=1024)?"css/layout1024":"css/layout800";
p.href = (w>=1280)?"css/playout1280.css":(w>=1024)?"css/playout1024":"css/playout800";
 
What exactly is your problem? You haven't said what isn't working.

Is it the screen width detection? Is the browser not including the right files? Or is the layout hosed, in which case, it's probably a CSS question?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
The problem is as soon as I put a doctype tag into the html, that stops working.
Without the doctype, it's good, so it's not the CSS. And the rest of the script works, so it's not that the script has been disallowed. :S
Could be the syntax? But I'm newish to scripting, so I'm not too sure. Lol.
Sorry if this isn't clear enough :S
 
The problem is as soon as I put a doctype tag into the html, that stops working.

But [!]what[/!] is it that isn't working? Saying "that" stops working still doesn't give us much of a clue.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Also, 3 things to note:

1: You don't have any "fall back" logic... so no CSS will load at all if the screen resolution is less than 800px wide. Granted, having a screen resolution of < 800px wide is rare these days, but you should still load something, I'd say.

2: Don't confuse screen resolution with browser real-estate. Many users don't surf with full-screen browsers.

3: Do you really need different CSS per resolution? Can't you just scale things nicely?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top