Results 1 to 4 of 4

Thread: Calling CSS with a function?

  1. #1
    Join Date
    Jun 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Calling CSS with a function?

    Does anybody know how this would work? I can't figure out how to call the css

    function resize()
    {

    if (screen.width >=640) {
    img.banner.src=banner640.jpg;
    document.write(<LINK HREF="style640.css" REL=Text/CSS>);
    }

    else if (screen.width >=800) {
    img.banner.src=banner800.jpg;
    document.write(<LINK HREF="style800.css" REL=Text/CSS>);
    }

    else if (screen.width <= 1040) {
    img.banner.src=banner.jpg;
    document.write(<LINK HREF="style.css" REL=Text/CSS>);
    }

  2. #2
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    Did you forget to place quotes around the text or did you do that by purpose??

    Try this:

    Code:
    function resize(){
    if (screen.width >=640) {
    img.banner.src = "banner640.jpg";
    document.write("<link rel='stylesheet' type='text/css' href='style640.css' />");
    } else if (screen.width >=800) {
    img.banner.src = "banner800.jpg";
    document.write("<link rel='stylesheet' type='text/css' href='style800.css' />");
    } else if (screen.width <= 1040) {
    img.banner.src = "banner.jpg";
    document.write("<link rel='stylesheet' type='text/css' href='style.css' />");
    }
    And by the way please don't forget to place [\CODE][/CODE] tags around your codes.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You shouldn't be doing this. The banner resizing is understandable, but using a different stylesheet based on screen resolution is a very bad idea. Using Javascript to choose that stylesheet is an even worse one. Redesign your site, and do it properly this time.
    shachi: Don't convert code to XHTML from HTML. See http://www.hixie.ch/advocacy/xhtml for reasons not to use XHTML -- quite aside from the fact that if the OP is using HTML, s/he is probably using an HTML doctype.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Thanks!!

    Thanks Twey for the link, going through it.

Bookmarks

Posting Permissions

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