Jump between PCs and mobile phones based on JavaScript code,

Source: Internet
Author: User

Jump between PCs and mobile phones based on JavaScript code,

This code is stored in the PC template code.

<Script type = "text/javascript"> // platform, device, and operating system var system = {win: false, mac: false, xll: false }; // detection platform var p = navigator. platform; system. win = p. indexOf ("Win") = 0; system. mac = p. indexOf ("Mac") = 0; system. x11 = (p = "X11") | (p. indexOf ("Linux") = 0); if (system. win | system. mac | system. xll) {} else {window. location. href = "Mobile Website" ;}</script>

This code is stored in the mobile website template.

<Script type = "text/javascript"> // platform, device, and operating system var system = {win: false, mac: false, xll: false }; // detection platform var p = navigator. platform; system. win = p. indexOf ("Win") = 0; system. mac = p. indexOf ("Mac") = 0; system. x11 = (p = "X11") | (p. indexOf ("Linux") = 0); if (system. win | system. mac | system. xll) {window. location. href = "pc url";} else {}</script>

PS: JS determines the redirection code on the mobile phone end and PC end

var browser_class = navigator.userAgent; var browser_class_name1 = browser_class.match("Mobile"); var browser_class_name2 = browser_class.match("mobile"); var location_url = window.location.href; if (browser_class_name1 != null || browser_class_name2 != null){     if (location_url.match("wap") == null){     window.location.href="http://wap.xxxx.com";     } } else {    if (location_url.match("3g") != null || location_url.match("wap") != null){    window.location.href="http://wap.xxxx.com";    } }

The above content is a summary of the JavaScript code-based jump between the pc and the mobile phone, I hope you like it.

Articles you may be interested in:
  • Difference between getRequestDispatcher () and sendRedirect () redirection in jsp
  • Several methods for implementing page redirect in js
  • How to Implement js and jquery scrolling/redirecting a page to a specified position
  • Baidu judges mobile terminals and automatically redirects JavaScript code and uses instances
  • Js listens to mouse clicks and keyboard click events and automatically jumps to the page
  • Js click the button to jump to another new page
  • JS automatically jumps to the login page after page timeout
  • How does js determine whether to log on or not and determine whether to jump to the page?
  • Share two mobile phone access pc websites automatically jump to mobile terminal website code
  • Examples of js judgment on mobile phone access or PC (usually used for mobile jump)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.