Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #23676
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Mobile Redirect |
| Date | 2014-03-25 21:49 +0100 |
| Organization | PointedEars Software (PES) |
| Message-ID | <2277541.GcSkzTRSRy@PointedEars.de> (permalink) |
| References | <lgsdo7$3va$1@news.albasani.net> |
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
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