Click to See Complete Forum and Search --> : Resolution dectection with CSS file


WhiteGumby
10-25-2003, 10:06 AM
ok here is what I scripted:

<SCRIPT LANGUAGE="JavaScript">
<!--
if ((screen.width>=1024) && (screen.height>=768))
{
document.write('<link href="/zayne/style1024.css" type=text/css rel=StyleSheet>');
}else{
document.write('<link href="/zayne/style800.css" type=text/css rel=StyleSheet>');
}
-->
</script>

ok well I'm trying to find the users resolution and then print the css file link into there. but nothing shows up, the page is blank. got any ideas?

Khalid Ali
10-25-2003, 10:26 AM
Yes,
The use of document.write() writes the link eleent once the page is loaded which means that everything that you had on the page is written over.

use DOM methods to add a new element with
document.createElement("link")
and set attributes...

WhiteGumby
10-25-2003, 07:22 PM
I'm really new to javascript and have no idea what DOM is. Do you know of any sites that would explain it? Or Could you quickly give me the lowdown of it?

Jona
10-25-2003, 07:29 PM
<script type="text/javascript"><!--
/* Untested code. */
if((screen.width>=1024) && (screen.height>=768)){
&nbsp;var cssSRC = "/zayne/style1024.css";
} else {
&nbsp;var cssSRC = "/zayna/style800.css";
}

var link = document.createElement("LINK");
var head = document.getElementsByTagName("HEAD")[0];
&nbsp;link.setAttribute("rel","StyleSheet");
&nbsp;link.setAttribute("type","text/css");
&nbsp;link.setAttribute("src",cssSRC);
&nbsp;head.appendChild(link);
//--></script>


[J]ona

WhiteGumby
10-27-2003, 03:23 AM
Thanks a lot for the script! I just had to change the "src" attribute to "href". Thanks again!

Jona
10-27-2003, 11:50 AM
My mistake, I don't often use the LINK element.

[J]ona