开发者

How to auto load mobile page when the site detect visitor is using mobile phone?

开发者 https://www.devze.com 2023-03-22 07:40 出处:网络
Is there any specific script / plugin which can do this? I am thinking along the line of creating a specific template /

Is there any specific script / plugin which can do this?

I am thinking along the line of creating a specific template / component for this purpose.

Then when user access the site homepage开发者_开发问答 will be routed to this specific template / component.

In the event that user still want to access the full information they can still access the other desktop version link directly.


You can use the BrowserDetect script found here to detect both the browser and operating system that the client is using. Then, depending on the result, you can do two different things:

  1. Change the classes on some important DOM nodes to change the look/feel of the page
  2. Change the window.location to force a redirect to a browser-based version of your site.

It's important to note that any solution you find in JavaScript won't work for anyone with JavaScript disabled. This sort of functionality is best handled server-side (Using PHP, Ruby, Python, or whichever language your application is written in). Doing it server-side has two distinct advantages:

  1. Users with JavaScript disabled will still get the proper version of the website.
  2. You can avoid additional entries in the users browser history by returning an HTTP 301 Redirect to the proper location.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号