I have been using an Embedded style sheet in a large number of pages on my site. I want to adjust the font sizes for different resolutions. I know I can use javascript to load different style sheets dependent upon screen res. but if I do that I will have to go through every single file that loads my embeded style sheet and add the javascript.
Is it posible to use a few lines of javascript within the style sheet to use different settings for different screen res? or do I just have to make another style sheet for each different res. and put that small bit of javascript into all of my pages?
Originally posted by shutuped do I just have to make another style sheet for each different res. and put that small bit of javascript into all of my pages?
Yes. You cannot mix JS and CSS in a style sheet file.
Just for the record, while you can't put JavaScript inside a .css file, you can put CSS in a .js file. I know it doesn't really help you, as you would have to change all your .css links to a .js link, but I thought I'd let you know. If you need an example of how this is done, let me know.
JavaScript is popular enough that I don't see this as a problem. You could add a simple script that lets people know that they need a JavaScript enabled browser. I doubt many people are using browsers that are old enough to warrent not using this meathod. The only problem that I would forsee is people who have JavaScript turned off. But, you could also redirect them to a page telling them they need to turn it on. I suppose if you are designing so that everyone can see it, you should never use JavaScript. Correct me if I'm wrong on this...because I'm thinking about making the navigation (and actually the viewing) of a site totally dependent on the fact the enough people have JavaScript to do this.
Just for the record, the last number I saw cited 12% as the precentage of internet users who do not use JavaScript. That's a huge number of people and I'm one of them. Some people turn it off because much of what bad web authors do with JavaScript makes the page inaccessible to persons with their disabilities. I turn it off because bad web authors keep making their pages annoying.
Yes, what Charles said is correct.
These are the stats for November 2002, available at http://www.thecounter.com/stats/2002/November/javas.php . The Counter is used as a fairly reliable statistics logger, because it monitors several hundred million hits per month, more than enough to sample an environment.
JavaScript Stats
Fri Nov 1 00:05:01 2002 - Sat Nov 30 23:55:05 2002 30.0 Days
I don't know where the other 2% are gone, I didn't write this. But see the numbers of hits for yourselves.
Why? Many people browse from schools and universities, which don't enable JavaScript.
Others believe "good advice" from losers. For example, Reader's Digest published something like this in a heavily-advertised useless computer manual ("How to manage your finances using a spreadsheet"-type of thing):
"Hints and tips: Java and JavaScript are used in web pages to create flashing titles and animated text. Follow these simple steps to disable those polluters and save your eyesight!"
Bookmarks