Home › Forums › JavaScript › Screen resolution detect and redirect to URL w/ manual switch back
- This topic is empty.
-
AuthorPosts
-
July 17, 2013 at 12:41 pm #46482owlinargyleParticipant
We have a Classic site and a Mobile site. (I know that this is old school, and would better done with two versions of CSS, but this is an old site. Unfortunately, I have to work with what they have until I can convince them to redesign.)
I added a Javascript that would detect the screen size of a mobile device and automatically redirect to our Mobile site. However, we also want to give the user the option to go back to the Classic site. But if you click on that link, it will just keep redirecting you back to the mobile version. Obviously, that won’t do.
I think I found another JavaScript that will do what I need, but it won’t work for me. I’m sure its something simple I’m overlooking. =( …I’ve set it up on [CodePen.](http://codepen.io/downcasteyes/pen/EGrIp “”)
Can someone take a look and point me in the right direction? I’d really appreciate it. Thanks!
July 17, 2013 at 1:38 pm #143382TheDocMemberI think this has to do with cookies more than anything, but that’s something I’ve never dealt with.
July 17, 2013 at 3:13 pm #143391owlinargyleParticipantWe don’t want to affect the user’s cookies. I did read something about using HTML5’s _sessionStorage_ but I don’t fully understand how to make it work for this specific instance.
July 18, 2013 at 2:36 pm #143511owlinargyleParticipantI found [this](https://github.com/sebarmeli/JS-Redirection-Mobile-Site “this”) , which may work. It’s a little over my head though.
July 18, 2013 at 2:47 pm #143513TheDocMemberLooks like a pretty good solution, actually!
Any reason why you don’t just want to use cookies?
July 19, 2013 at 10:29 am #143728owlinargyleParticipantI think we were just trying to stay away from affecting the users’ browser settings. But we may not have any other way around it. I’ve spent the last few days researching, and so far most of the other scripts I’ve found are very similar to this one, though this one seems the most thorough.
July 19, 2013 at 10:32 am #143729owlinargyleParticipantFound this [old discussion](https://css-tricks.com/forums/discussion/13960/detect-mobile-and-redirect/p1 “old discussion”) on here too, that’s along the same lines as to what I’m trying to do. Glad to see I’m not the only one faced with this issue. =)
July 19, 2013 at 11:50 am #143736Kitty GiraudelParticipant@chriscoyier wrote something about it: https://css-tricks.com/user-opt-out-responsive-design/.
July 22, 2013 at 9:18 am #144075owlinargyleParticipantAugust 28, 2013 at 1:22 pm #148443toma888Participantdowncasteyes,
I’m using a basic HTML site and need the code for a mobile redirect as well as let the user click on a link
to view full site.
I’m currently using this code:if (document.location.search.indexOf(“skipmobile”) >= 0) {
document.cookie = “skipmobile=1”;
}
else if ((document.location.hostname.match(/.mobi$/) || screen.width < 699)
&& document.cookie.indexOf("skipmobile") == -1)
{
document.location = "http://dacopywriter.com/mobile-3/index.html";
}and it works fine but will not validate in W3C:
(required attribute “type” not specified )Do you have some clean code that I can just drop into the ?
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.