admin管理员组文章数量:1332389
I have a CV/Resume site and when a user visits my website and the screen resolution is lower than 960 I redirect him to my mobile site through this JS
<script type="text/javascript">if (screen.width <= 960) {document.location = mobile.html";}</script>
My question is if the user wants to visit the normal site and hit a link the javascript will run again and it will redirect the user back to the mobile site. One method to solve this problem it could be to duplicate the normal site lets say index.html and index1.html one with the above code and one with no JS but i think this solution is so noobish. Any way to solve this problem? Before you answer please note that i have no access to the .htaccess file.
My problem is when a user visits my site with scree width lower than 960 go to mobile site but if he wants to see the full site press a link and get redirected to the full site no matter the screen width.
I have a CV/Resume site and when a user visits my website and the screen resolution is lower than 960 I redirect him to my mobile site through this JS
<script type="text/javascript">if (screen.width <= 960) {document.location = mobile.html";}</script>
My question is if the user wants to visit the normal site and hit a link the javascript will run again and it will redirect the user back to the mobile site. One method to solve this problem it could be to duplicate the normal site lets say index.html and index1.html one with the above code and one with no JS but i think this solution is so noobish. Any way to solve this problem? Before you answer please note that i have no access to the .htaccess file.
My problem is when a user visits my site with scree width lower than 960 go to mobile site but if he wants to see the full site press a link and get redirected to the full site no matter the screen width.
Share asked Jan 2, 2012 at 0:20 SonamorSonamor 2313 silver badges17 bronze badges 1- when the user hits the "normal" site, check if some cookie exists, if so, don't redirect, on the mobile website, when the user wants to be redirected to the "normal" site, create a cookie before redirecting. – user497849 Commented Jan 2, 2012 at 0:25
2 Answers
Reset to default 5Here's a small code snippet. When the user changes from mobile to normal, run the following code:
var expires = new Date();
expires.setHours(expires.getHours + 24);
document.cookie = (document.cookie ? document.cookie + ' ;' : '')
+ ' disableMobile=1; expires=' + expires.toGMTString();
and then change your redirect condition to
if (screen.width <= 960 && document.cookie.indexOf('disableMobile') < 0) [...]
Two ways e to mind:
- Use a cookie, so that the user's preference to stay on the full site will be remembered. Create/set the cookie just before redirecting.
- Use a query parameter,
<a href="index.html?fullsite=true">Full site</a>
(or similar), which you set only in the link frommobile.html
back to the normal site.
Then add a condition to your existing screen width test so that it only runs if the cookie/query parameter is not set.
(You may also like to add an extra link on your main index page to let the user choose the mobile version. Obviously if you go the cookie route this should clear the cookie.)
本文标签: javascriptMobile to Normal website RedirectStack Overflow
版权声明:本文标题:javascript - Mobile to Normal website Redirect - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742290927a2447780.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论