SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Apr 2003
    Location
    spain
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Window resize script not calling css codes

    Hi, I'm trying to use this javascript code to resize the window, but I must be doing something wrong. It doesn't call my css pages (cs.css and mobile.css). Any help appreciated. I do have those css pages uploaded.
    Code:
    <body>
              
       <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
        <script type=”text/javascript”>
    $(document).ready(function(){
    $(window).bind(“resize”, resizeWindow);
    function resizeWindow(e){
    var newWindowWidth = $(window).width();
    // If width width is below 600px, switch to the mobile stylesheet
    if(newWindowWidth < 600){                 $(“link[rel=stylesheet]“).attr({href : “mobile.css”});  } 
    // Else if width is above 600px, switch to the large stylesheet             else if(newWindowWidth > 600){
    $(“link[rel=stylesheet]“).attr({href : “cs.css”});
    }
    }
    });
    </script>
    
     <div id="pagewrap">
    <div id="container">
    	<div id="header">

  2. #2
    SitePoint Member shortcircuit's Avatar
    Join Date
    Jan 2012
    Location
    SW Arizona
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since I can't post links yet, suggest you do a Google search for "javascript code to resize window" as there's numerous solutions you can view.

  3. #3
    SitePoint Addict
    Join Date
    Apr 2003
    Location
    spain
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But, could you let me know if there's some mistake in the code I posted, which might cause it not to work? I wanted to use it for media queries, especially for

    IE 6 etc, the idea being to call a separate stylesheet for screens smaller than 600 px wide. Thanks.


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
  •