Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #23670 > unrolled thread
| Started by | Jeff Thies <jeff@thelimit.com> |
|---|---|
| First post | 2014-03-25 13:18 -0400 |
| Last post | 2014-03-25 21:49 +0100 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.lang.javascript
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
| From | Jeff Thies <jeff@thelimit.com> |
|---|---|
| Date | 2014-03-25 13:18 -0400 |
| Subject | Mobile Redirect |
| Message-ID | <lgsdo7$3va$1@news.albasani.net> |
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.
So:
function runSwitchLink(){
if(window.screen.width < 800){
if(!document.getCookie('asked')){
document.write('<a href="javascript:location.href=' +
"'http://mobile.some-site.com/mobile_redirect.php'" + '"
class="asked">Switch to Mobile Site</a>');
document.cookie = 'asked=yes;path=/';
}
}
}
runSwitchLink();
// document.getCookie defined elsewhere
Site requires cookies (cart), so cookies off is not an issue.
I think screen.width takes into account dppx oversampling, and I think
it is available always, even before page load. Is this right?
Other ideas?
Jeff
[toc] | [next] | [standalone]
| From | Danny <dann90038@gmail.com> |
|---|---|
| Date | 2014-03-25 11:32 -0700 |
| Message-ID | <90a1b24d-967e-45d1-b843-3af35ff8e2f0@googlegroups.com> |
| In reply to | #23670 |
To Jeff Thies yes it's available even before Body loads since he's already redirecting to a mobile version I assume there's a desktop and mobile sites being served so what you're doing is ok otherwise you could just use CSS3 @media queries http://mobile.smashingmagazine.com/2010/07/19/how-to-use-css3-media-queries-to-create-a-mobile-version-of-your-website/ to cater for different resolutions and viewports
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-03-25 19:39 +0100 |
| Message-ID | <XnsA2FBC803FEF71eejj99@194.109.133.133> |
| In reply to | #23672 |
Danny <dann90038@gmail.com> wrote on 25 mrt 2014 in comp.lang.javascript: > To Jeff Thies Wrong, this is usenet. If you want to email, email him. If you respond here, respond to the group and quote what you are responding on. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-03-25 21:49 +0100 |
| Message-ID | <2277541.GcSkzTRSRy@PointedEars.de> |
| In reply to | #23670 |
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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web