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


Groups > comp.lang.javascript > #23676

Re: Mobile Redirect

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Mobile Redirect
Date Tue, 25 Mar 2014 21:49:27 +0100
Organization PointedEars Software (PES)
Lines 94
Message-ID <2277541.GcSkzTRSRy@PointedEars.de> (permalink)
References <lgsdo7$3va$1@news.albasani.net>
Reply-To Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace solani.org 1395780571 22839 eJwFwQkBACAIA8BKCGNqHPn6R/DOjYu5QSd8fG4vI1RoXgx0FnlEKqK7sVPP8L4SB8Ve6gcUWhD8 (25 Mar 2014 20:49:31 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Tue, 25 Mar 2014 20:49:31 +0000 (UTC)
User-Agent KNode/4.11.5
X-User-ID eJwNyscBwDAIBLCVaEcZx8aw/wiJ3oI6e4c53LDYpZg3zbeAo/FG2UtocJNYqkcNASR8kYeapsS54l2T+P8HSegUsw==
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==
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Cancel-Lock sha1:83wpjHokVRmAaTeX9BD/p8o4OBg=
X-NNTP-Posting-Host eJwFwYEBwCAIA7CXQCi4cyqz/59ggiiv6SxUQhBHduwXNp12Q7BgkNo9vFR5zErlQp+v6A87JRHU
Xref csiph.com comp.lang.javascript:23676

Show key headers only | View raw


Jeff Thies wrote:

>    I have a client with a site that has a mobile subdomain.
> 
>    There are a number of ways to redirect and an unholy number of devices.
> 
> What I thought was to through up a large mobile type link once. There is
> a mobile link in a normal font elsewhere.

It certainly is better than automatic redirection, which is frowned upon, 
but it is still a bad idea.
 
> So:
> 
> function runSwitchLink(){
> if(window.screen.width < 800){

“screen” is not designed to be a property of the object referred to by 
“window” (and if you think about it, it would not make sense: the window is 
on the screen, not vice-versa). 

<http://www.w3.org/TR/html5/browsers.html#the-window-object>

In DOM Level 0, it is just “screen.width”:

<http://docs.oracle.com/cd/E19957-01/816-6408-10/>

> if(!document.getCookie('asked')){

Document objects do not have a built-in getCookie() method in any DOM 
implementation (not even in HTML5 [1]; but it would be good if they had one 
that worked like this).  Therefore, if this works, augmentation of the 
referred object must have taken place.  It is a host object; you should not 
attempt to augment it, and you should avoid libraries that do.

[1] <http://www.w3.org/TR/html5/dom.html#the-document-object>

> document.write('<a href="javascript:location.href=' +
> "'http://mobile.some-site.com/mobile_redirect.php'" + '"
> class="asked">Switch to Mobile Site</a>');

  document.write(
      '<a href="http://mobile.some-site.com/mobile_redirect.php">'
    + ' class="asked">Switch to Mobile Site<\/a>');

and then drop the whole idea.  Do not believe Googlodyte wannabes telling 
you that what you are doing (or attempting to do) is OK.  It is not.
 
> document.cookie = 'asked=yes;path=/';

There is window.localStorage now, especially on mobile devices.  In any case 
you will need to ask permission from the user and inform them that you are 
using cookies and similar techniques to store personal information.

> }
> }
> }
> 
> runSwitchLink();

There is no point in using a function if the function is called only once 
just after it was declared and contains no variable declarations.

> // document.getCookie defined elsewhere

AISB.
 
> Site requires cookies (cart), so cookies off is not an issue.

Cookies have no intrinsic relationship to client-side scripting (they are 
primarily an HTTP feature), and your Web shop better also works without 
client-side scripting.
 
> I think screen.width takes into account dppx oversampling, and I think
> it is available always, even before page load. Is this right?

I do not know what you mean by “dppx oversampling”; probably you have been 
reading too many wannabe blogs, and are now under the delusion that you know 
something they call “Javascript”.  In any case, instead of asking the 
question you could just have tested it.

However, I strongly suggest that you never use screen.*width to decide such 
questions because it does not give you the right answer in any case.  
Therefore, you are asking the wrong question.
 
> Other ideas?

Do not crosspost into or outside of the Big 8.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

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


Thread

Mobile Redirect Jeff Thies <jeff@thelimit.com> - 2014-03-25 13:18 -0400
  Re: Mobile Redirect Danny <dann90038@gmail.com> - 2014-03-25 11:32 -0700
    Re: Mobile Redirect "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-25 19:39 +0100
  Re: Mobile Redirect Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-25 21:49 +0100

csiph-web