Mobile forwarding

I have a CV / Resume site, and when a user visits my site and the screen resolution is below 960, I redirect it to my mobile site through this JS

<script type="text/javascript">if (screen.width <= 960) {document.location = mobile.html";}</script> 

My question is whether the user wants to visit a regular site and click on the link that javascript will launch and redirect the user to the mobile site. One way to solve this problem could be to duplicate a regular site, say index.html and index1.html, one with the above code and one without JS, but I think this solution is so Nubian. Any way to solve this problem? Before answering, please note that I do not have access to the .htaccess file.

My problem is that a user visits my site with a scree width below 960 by going to a mobile site, but if he wants to see the full site, click on the link and redirect to the full site regardless of screen width.

+4
source share
2 answers

Here is a small piece of code. When the user switches from mobile to regular, 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 the redirection condition to

  if (screen.width <= 960 && document.cookie.indexOf('disableMobile') < 0) [...] 
+5
source

Two ways come to mind:

  • Use a cookie to keep user preferences on the full site. Create / configure a cookie just before the redirect.
  • Use the request parameter <a href="index.html?fullsite=true">Full site</a> (or similar), which you set only in the link from mobile.html to the regular site.

Then add the condition to the existing screen width test so that it runs only if the cookie / query parameter is not set.

(You may also need to add an additional link on the index home page so that the user can select the mobile version. Obviously, if you follow the cookie path, this should clear the cookie.)

+3
source

Source: https://habr.com/ru/post/1388865/


All Articles