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)