0

How do you redirect all users on your website, except those browsing on a mobile or tablet? I want to use PHP or JavaScript.

I've tried a few snippets but can't find something that fits my use case - I've only found scripts that redirect mobile users or everyone, no matter what device.

nikobelia
  • 3,775
  • 1
  • 16
  • 26

3 Answers3

0

use one of the scripts that perform mobile detection and simply only redirect if a mobile device is not detected.

Damian Nikodem
  • 1,274
  • 10
  • 26
0

As far as I know there isn't a foolproof way to do it in Javascript yet - this question sets out two decent approaches, one which grabs the user agent string from the client and one that gets the device width. They each have pros and cons - user agent strings are subject to change, device width leaves you a bit open to confusion on mid-sized devices like tablets; depends on your use case which one works for you.

In terms of how to redirect desktop but not mobile users - both of these solutions are ways of detecting what the user's device is, then storing that information in a variable in Javascript. What you need to do from there is script that redirect behaviour for the group of users you want to move. Google if-statements and "window.location" and you'll find plenty of information out there on how to do that.

Community
  • 1
  • 1
nikobelia
  • 3,775
  • 1
  • 16
  • 26
-1

use the scripts provided in here, to detect and include/exclude mobile users:

user 12321
  • 2,454
  • 20
  • 34