www.webdeveloper.com
Results 1 to 3 of 3

Thread: how can I redirectto another html file from css?

  1. #1
    Join Date
    Jul 2012
    Location
    Vantaa, Finland
    Posts
    125

    how can I redirectto another html file from css?

    I have a website that has 4 separate versions for different size screens. Pretty grim even if it's bad to be different!

    I have now finished programming my first site but there's some work to go before it's responsive.

    Until the site is responsive what I want to do is have a css file that uses @media to detect a screen size and then redirect/load from the appropriate folder.

    i.e
    @media only screen and (min-width: 480px) {
    open file: /directory/file.html;
    }

    Is there a way to do this?

  2. #2
    Join Date
    Sep 2006
    Location
    new york
    Posts
    265
    See for instance http://css-tricks.com/css-media-queries/

    Believe the @media is used to change the CSS. To actually re-direct to another page you would use some JavaScript such as

    Code:
    <script type="text/javascript">
    <!--
    if (screen.width <= 699) {
    document.location = "indexmobile.html";
    }
    //-->
    </script>
    P.S. Webdeveloper.com has a forum for "Mobile Web Development" http://www.webdeveloper.com/forum/fo...eb-Development -- which might have some helpful posts
    Last edited by auntnini; 10-13-2012 at 05:11 PM. Reason: add reference to other forum

  3. #3
    Join Date
    Jul 2012
    Location
    Vantaa, Finland
    Posts
    125
    Thanks for your reply. It's states the obvious, which I didn't think of.

    I used the javascript that you gave in my old website but I had this on every html page.

    I read somewhere that this slows down the download times as cache isn't used. Thus begun my turbulant voyage of learning to program my own site.

    What I have just found out is that what I should have done was put the javascript in a separate file and linked to it from the html file. That makes life so much easier!

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