Skip to content

Instantly share code, notes, and snippets.

Forked from niksmac/detect-mobile-browser.js
Created June 2, 2016 07:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jwebcat/e3f621ddff7c89c6aa7d32b50d7083a5 to your computer and use it in GitHub Desktop.
Nodejs Express code to redirect mobile user agets
var express = require('express'),
app = express();
app.get('/', function(req, res){
var ua = req.header('user-agent');
// Check the user-agent string to identyfy the device.
if(/mobile|iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile|ipad|android|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i.test(ua)) {
res.sendfile(__dirname + '/mobile.html');
} else {
res.sendfile(__dirname + '/index.html');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment