1

I'm working on a website and want to make it mobile friendly. I thought it would be nice to redirect the mobile devices to an extra subdomain. The concept is following.

How to detect that it is a mobile device?

Checking with Javascript if the device is bigger than 1000px like this:

if (screen.width <= 1000) {
document.location = "mobile.html";}

I'm not so good in Javascript so I dont know if there is an option to redirect to an URL instead of a document.

I have read that it is possible with the .htacces file but I have no clue how this code works which is in this file. Often there is no explanation how it detects mobile devices. I don't want some link with "Go here to mobile version".

ChrisM
  • 1,440
  • 6
  • 15
  • 27
Devi
  • 89
  • 1
  • 10
  • " I thought it would be nice to redirect the mobile devices to an extra subdomain." — It isn't. It means you have two sites to maintain and one is likely to get out of date. Just create a responsive design. – Quentin Dec 12 '17 at 15:05

1 Answers1

2

To detect if the user is on a mobile I advise you read this thread as it presents a way to detect mobile users far more reliable than checking the screen size

The MSDN doc shows that you can simply put an URL in the document.location var as follow

if (screen.width <= 1000)
    document.location = 'mobile.mydmain.com' 
Mathieu VIALES
  • 3,852
  • 2
  • 22
  • 44