Forum Moderators: open

Message Too Old, No Replies

JavaScript to change style sheet

         

field4000

8:38 pm on Mar 21, 2005 (gmt 0)

10+ Year Member



Hi,

I was wondering if anybody had a simple javascript to detect the user's screen resolution then change the style sheet accordingly.

I have two style sheets that I want to use - one for hi-res and one for low-res.

I just do not know how to call the relevant one when needed.

Cheers in advance.

mcibor

2:54 pm on Mar 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How to check screen resolution I don't know, but what's even better you can check screen width and height:

var x = screen.width;
var y = screen.height;

How to change style then I am unsure. It has sth to do with document.style, however I forgot the proper syntax (I usually use this.style.backgroundColor='rgb(0,0,0)';)

Hope this helps a bit.

Best regards
Michal Cibor

On the other hand I just read:
Replacing Style Sheets
You can replace one style sheet with another by setting the href property of the style sheet to the URL of the replacement, as in the following example:

if (document.styleSheets(0).href!= null)
document.styleSheets(0).href = "newstyle.css";

More of this on:
[msdn.microsoft.com...]

Moby_Dim

4:08 pm on Mar 22, 2005 (gmt 0)

10+ Year Member



sorry, have not read the entire reply