Path: csiph.com!2.us.feeder.erje.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Redirecting to a mobile site Date: Fri, 02 Dec 2016 16:46:17 +0100 Organization: PointedEars Software (PES) Lines: 43 Message-ID: <8027209.CDJkKcVGEf@PointedEars.de> References: <88e1893c-1452-4f95-80d5-b1636c17bd2c@googlegroups.com> <167p9jhlr6kuu$.6xt7ynx0ui1w.dlg@40tude.net> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: solani.org 1480693578 32461 eJwFwYEBwCAIA7CXQGiZ5+ig/59ggqDzrySYEKSbvfdMqu07papAeHnCRn4UQWNgrbYSLx4fohCp (2 Dec 2016 15:46:18 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Fri, 2 Dec 2016 15:46:18 +0000 (UTC) User-Agent: KNode/4.14.2 X-NNTP-Posting-Host: eJwFwYEBgDAIA7CXQIFu5yC0/59gkm95DaKyIpXiJq7ma28y2qS7VGEJ41hKjfEW8cQ5bj9QpBKK Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== Cancel-Lock: sha1:mvw9dVv/LWeqjcrJz4dF0iERuMI= X-User-ID: eJwNy8EBwCAIA8CVBA3gOBhg/xHa+x+2idGPwQ4G06LXM5hEb0Z7sq+mpkgiXq9SFJ6xKqyU6tFTclmz/ssPfAYW2g== X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. 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. > > > 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: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.