www.webdeveloper.com
Results 1 to 8 of 8

Thread: Using Javascript in an Embedded CSS

  1. #1
    Join Date
    Dec 2002
    Posts
    1

    Talking Using Javascript in an Embedded CSS

    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?

    any ideas would be apriciated

  2. #2
    Join Date
    Nov 2002
    Posts
    4,473
    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.

  3. #3
    Join Date
    Nov 2002
    Posts
    984

    Re: Using Javascript in an Embedded CSS

    Originally posted by shutuped
    [B] I want to adjust the font sizes for different resolutions.
    Why not just leave that up to the user?

    I'm sure they are perfectly capable of setting a screen resolution and default fontsize that works just fine for them
    // Stefan Huszics

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    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.

  5. #5
    Join Date
    Nov 2002
    Posts
    984
    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.
    A word of caution... with such a solution if JS is not available in the visitors browser you are **cked
    // Stefan Huszics

  6. #6
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    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.

  7. #7
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,270
    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.

  8. #8
    Join Date
    Dec 2002
    Location
    Perth, Western Australia
    Posts
    55
    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

    Javascript 1.2+: 309600823 (88%)
    Javascript <1.2: 848682 (0%)
    Javascript false: 38101069 (10%)


    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!"

    That nearly made me cry.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles