简体   繁体   中英

Landing page with Express and nodejs

I just bought a HTML landing page and I am totally newbie with all of this...

There are 3 different folders : /windows /ios /android

How can I use nodejs and express to display the landing page? I mean, how to redirect the client to /ios if he uses an iPhone for example.

There are two ways of going about this: you would detect the browser/platform type on the client side ( here ) or server side ( here ). You would, then, send that information over to the server side so that you can render the appropriate static assets based on that information.

For rendering static assets in Node.js, refer here

@Detuned posted some really good links that answer your question.

Basically, you'd want to check the userAgent and render a page based on where they're coming from.

The userAgent names aren't correct, or shouldn't be since i've not checked them but i'd expect something similar to this :

app.get('/', function(req, res) {

  var userAgent = req.headers['user-agent'];

  if (userAgent.startsWith('Mozilla') || userAgent.startsWith('Chrome') || userAgent.startsWith('Explorer')) {

      res.render('index_windows', {})

  } else if (userAgent.startsWith('iOS')) {

      res.render('index_ios', {})

  } else if (userAgent.startsWith('android')) {
      res.render('index_android', {})
  }
  else {
   res.render('index_windows', {})
  }
});

This basically grabs the / which is your home url like www.example.com/ and does a check on the headers to determine where the user has come from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM