Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #31762

Re: Redirecting to a mobile site

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Redirecting to a mobile site
Date 2016-12-02 16:46 +0100
Organization PointedEars Software (PES)
Message-ID <8027209.CDJkKcVGEf@PointedEars.de> (permalink)
References <88e1893c-1452-4f95-80d5-b1636c17bd2c@googlegroups.com> <167p9jhlr6kuu$.6xt7ynx0ui1w.dlg@40tude.net>

Show all headers | View raw


JJ wrote:

> On Thu, 1 Dec 2016 09:42:13 -0800 (PST), bit-naughty@hotmail.com wrote:
>> ....I've been to sites, where, if you're on a mobile device, it redirects
>> you to say, m.site.com - how is this done? (the only knowledge *I* have
>> regarding anything about this is "media queries" in CSS - and that
>> doesn't explain the redirection....)
>> 
>> Thanks.
> 
> Not in CSS, but CSS media query.

Different wording, same concept.

> In JavaScript, you'd use `window.matchMedia()` to test a media query.

But that is not how this should be done.
 
> <https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia>
> 
> e.g. redirect if on handheld devices.
> 
>   if (window.matchMedia("handheld")) {
>     location.href = "https://m.thesite.com/";
>   }
> 
> Do this at the very first script.

And annoy your visitors to no end :->

The proper way is to tell visitors with mobile devices that a mobile-
optimized version is available for them unless they have switched from the 
mobile-optimized version to the desktop-optimized version (which is possible 
e.g. in Mobile Chrome by simply checking a checkbox in the menu).

As an alternative, media queries can be used so that the stylesheet is 
adapted to the mobile device and no mobile-optimized version is necessary.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Redirecting to a mobile site bit-naughty@hotmail.com - 2016-12-01 09:42 -0800
  Re: Redirecting to a mobile site Philip Herlihy <thiswillbounceback@you.com> - 2016-12-01 19:46 +0000
  Re: Redirecting to a mobile site Silvio <silvio@internet.com> - 2016-12-01 23:31 +0100
  Re: Redirecting to a mobile site JJ <jj4public@vfemail.net> - 2016-12-02 22:38 +0700
    Re: Redirecting to a mobile site Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-02 16:46 +0100
  Re: Redirecting to a mobile site Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2016-12-03 11:35 +0100
    Re: Redirecting to a mobile site Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-04 20:23 +0100
      Re: Redirecting to a mobile site Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2016-12-05 07:38 +0100
        Re: Redirecting to a mobile site Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-05 13:16 +0100

csiph-web