Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    Member mzee's Avatar
    Join Date
    Dec 2004
    Posts
    2,431

    Question Problem with script to divert to a phone friendly site

    In my website I have a script which diverts the viewer to a mobile friendly mini site. It is placed in the <header>.
    In this if the logged on screen is equal to or less than 750px wide it is diverted to ..../mobile/

    <!--
    if (screen.width <= 750) {
    window.location = "http://kenyapages.net.nz/mobile/";
    }
    //-->

    I want to do the same with other resolutions i.e 320 & 480.
    What is needed is:
    the logged on screen is equal to or less than 750px wide but not less than 480px it is diverted to ..../mobile/
    the logged on screen is equal to or less than 480px wide but not less than 320px it is diverted to ..../mobile/
    the logged on screen is equal to or less than 320px wide it is diverted to ..../mobile/

    I can then have several suitable mini sites.

    Help would be appreciated
    Last edited by mzee; 18-10-2016 at 02:12 PM.

  2. #2
    Member beama's Avatar
    Join Date
    Dec 2004
    Location
    where eye patches are worn with pride
    Posts
    1,724

    Default Re: Problem with script to divert to a phone friendly site

    this might save some time and server space use % instead of px instead of coding several different landing pages

    http://www.w3schools.com/css/css_dimension.asp
    Trust me. I know what I'm doing.Sledge Hammer

    Linux the only way to get rid of the windows boot sector virus ( Geoff Palmer , Jun 28, 2004 Tips & Help : Tux Love, PCWorld NZ)

    Parkinsons NZ


  3. #3
    Short Member pcuser42's Avatar
    Join Date
    Apr 2006
    Location
    Pukekohe Shuttle
    Posts
    10,066

    Default Re: Problem with script to divert to a phone friendly site

    Quote Originally Posted by beama View Post
    this might save some time and server space use % instead of px instead of coding several different landing pages

    http://www.w3schools.com/css/css_dimension.asp


    You would be much better off coding a responsive website rather than different pages for different devices.

    See also CSS media queries: https://developer.mozilla.org/en-US/docs/Web/CSS/@media
    "He who resorts to personal insults hath lost the argument."

    Twitter

  4. #4
    Member beama's Avatar
    Join Date
    Dec 2004
    Location
    where eye patches are worn with pride
    Posts
    1,724

    Default Re: Problem with script to divert to a phone friendly site

    Quote Originally Posted by pcuser42 View Post


    You would be much better off coding a responsive website rather than different pages for different devices.

    See also CSS media queries: https://developer.mozilla.org/en-US/docs/Web/CSS/@media
    yep. in the bad old days we used to use a table set that to 90 % of available screen real estate. Let the browser do the rendering and put all the content in the table. Made for some interesting layouts when the page displayed was on a screen with different resolutions. Much easier these days.
    Trust me. I know what I'm doing.Sledge Hammer

    Linux the only way to get rid of the windows boot sector virus ( Geoff Palmer , Jun 28, 2004 Tips & Help : Tux Love, PCWorld NZ)

    Parkinsons NZ


  5. #5
    Senior Member
    Join Date
    Dec 2004
    Posts
    1,131

    Default Re: Problem with script to divert to a phone friendly site

    I am sure I mentioned to you before mzee that you should use a framework to do the dirty work like bootstrap or foundation. You are just increasing your work by making seperate mini sites targetting different devices.

    I use to develop seperate sites too, sites that were in different languages, sites aimed at different devices. It was a nightmare to maintain.

    You should use a javascript library like jquery so you have browser compatible code to use.

    To answer you, you order your code from least likely to likely. So small to big and if no condition is met, a default page.

    I'm on my phone so i'll speak in psuedo

    if width is 320px or less goto here
    else if width 480px or less goto here
    else if ...
    else goto default

  6. #6
    Member mzee's Avatar
    Join Date
    Dec 2004
    Posts
    2,431

    Default Re: Problem with script to divert to a phone friendly site

    I have tried the responsive method but its more trouble than its worth. No problem making individual sites, if you use tables all you have to do is alter the template width, then tidy it up, change the name.
    This script works:
    script type="text/javascript">
    <!--
    if (screen.width <= 720) {
    window.location = "http://xxxx.net.nz/m1/";
    }
    if (screen.width <= 320) {
    window.location = "http://xxxx.net.nz/m2/";
    }

    //-->
    </script>

  7. #7
    Short Member pcuser42's Avatar
    Join Date
    Apr 2006
    Location
    Pukekohe Shuttle
    Posts
    10,066

    Default Re: Problem with script to divert to a phone friendly site

    Quote Originally Posted by mzee View Post
    if you use tables all you have to do is alter the template width, then tidy it up, change the name.
    I just got shivers down my spine... Using tables for layouts actually makes making responsive websites more difficult as they don't adapt to different screen sizes very well.
    "He who resorts to personal insults hath lost the argument."

    Twitter

  8. #8
    Senior Member
    Join Date
    Dec 2004
    Posts
    1,131

    Default Re: Problem with script to divert to a phone friendly site

    How does that script work correctly, its flawed at the start where anything less or equal to 720px goes to m1, 320px is less than 720px and makes that condition true.

    As I said, start small and work your way up. Otherwise I feel like i'm wasting my time if you won't listen.

  9. #9
    Senior Member
    Join Date
    Dec 2004
    Posts
    1,131

    Default Re: Problem with script to divert to a phone friendly site

    if (screen.width < 321) {
    window.location = "http://xxxx.net.nz/m320/";
    }
    else if (screen.width < 481) {
    window.location = "http://xxxx.net.nz/m480/";
    }
    else if (screen.width < 721) {
    window.location = "http://xxxx.net.nz/m720/";
    }
    else {
    window.location = "http://xxxx.net.nz/default/";
    }

  10. #10
    Member mzee's Avatar
    Join Date
    Dec 2004
    Posts
    2,431

    Default Re: Problem with script to divert to a phone friendly site

    Quote Originally Posted by Kame View Post
    if (screen.width < 321) {
    window.location = "http://xxxx.net.nz/m320/";
    }
    else if (screen.width < 481) {
    window.location = "http://xxxx.net.nz/m480/";
    }
    else if (screen.width < 721) {
    window.location = "http://xxxx.net.nz/m720/";
    }
    else {
    window.location = "http://xxxx.net.nz/default/";
    }
    This works well. Only problem is that some of the resolutions are not the same in practice. For instance, my son's Samsung Galaxy is suppose to be 720px across, but is actually 440px. I have done a few responsive sites which are good when you do frequent updates, or the site is a large one.

Similar Threads

  1. Googles New Mobile Phone Test Site
    By kahawai chaser in forum PC World Chat
    Replies: 0
    Last Post: 06-11-2011, 08:46 AM
  2. divert when busy
    By trevor in forum PressF1
    Replies: 2
    Last Post: 20-06-2004, 06:38 PM
  3. Replies: 0
    Last Post: 05-02-2003, 12:57 PM
  4. Make site more PC friendly!
    By DeeDee in forum PressF1
    Replies: 35
    Last Post: 05-08-2002, 08:39 PM
  5. Java-script problem?Maybe.
    By in forum PressF1
    Replies: 0
    Last Post: 16-06-2002, 11:39 PM

Posting Permissions

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