Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn 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> References: Reply-To: Thomas 'PointedEars' Lahn 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+&. 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). In DOM Level 0, it is just “screen.width”: > 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] > document.write(' class="asked">Switch to Mobile Site'); document.write( '' + ' 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.