Say someone has a webpage designed for desktops and decides they want the webpage to work properly for mobile devices. They want the desktop webpage to be left alone.
What is the script or method to detect a mobile webpage and load a new html/css for tablet/phone size . users will go to the same webpage as the desktop location and be redirected to a mobile version if need be.
This avoids the headache of making a static desktop webpage responsive.
05-23-2013, 11:56 PM
This is my first post here if I'm doing something wrong by sharing this snippet code, Moderator can delete this post and let me know Thanks
Add the following script on the head section of each page of the desktop website:
var _mobile_url = "http://yourdomain.com/mobilepath"; //Here Just add the path to your mobile content
var _screen_width = 800; // Here you specify the width of the devices you want to switch to the mobile website
var date = new Date();
var expires = "; expires="+date.toGMTString();
else var expires = "";
document.cookie = name+"="+escape(value)+expires+"; path=/";
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0; i < ca.length; i++)
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));