Con la llegada de 4G, los sitios web móviles están fuera de control, y las PC y los sitios web oficiales móviles coexisten. ¿Cómo hacer que otros visiten el sitio web oficial de su PC y salten directamente al sitio web móvil? Estimados lectores, ¡agregue el código! ¡Aquí viene!
Determinar si el navegador es un teléfono móvil
<script type = "text/javaScript"> (function () {var rewriteUrl = function (url) {if (url) {var diviste = url.split ("/"), siteName = window.location.pathname; if (typeof Sitename! == "Undefined") {return "https://m.vevb.com"+Sitename}}}; if (/android | webos | iPhone | iPad | windows phone | ipod | blackberry | symbianos | nokia | mobile/i.test (navigator.useragent)) {var url = window.latesation.href; var; PathName = Window.location.pathName; if (url.indexof ("? Pc") <0) {try {window.location.href = rewriteurl (url)} catch (e) {}}}}) (); </script>Para determinar si el navegador es una PC, salte a la página de la PC
<script> var browser1 = {versions: function () {var u = navigator.useragent, app = navigator.appversion; return {// mobile terminal Browser versión de la versión Trident: u.indexof ('trident')> -1, // ie kernel presto: u.indexof ('presto')> -1, // ópera kernel webkit: u.indexof ('applewebkit')> -1, // manzana y google kernel gecko: u.index ('obkeck) u.indexof ('khtml') == -1, // Firefox kernel mobile: !! u.match (/applewebkit.*Mobile/i) || !! u.match (/midp | symbianos | nokia | samsung | lg | nec | tcl | alcatel | bird | dbtel | dopod | philips | haier | lenovo | mot- | nokia | sonyericsson | sie- | amoi | zte/), // es un terminal móvil IOS: !! CPU.+Mac OS X/), // iOS Terminal Android: U.indexof ('Android')> -1 || U.IndexOf ('iPad')> -1, // es un iPad WebApp: U.IndexOf ('Safari') == -1 // se supone que debe programar, sin encabezado e inferior} (), Idioma: (navegator.browserLanguage || navigator.language) .tolowercase ()} if (browser1.versions.mobile == false && browser1.versions.ios == false && browser1.versions.android == false && browser1.versions.iphone == false && browser1.versions.ipad == false) {// ubicación.href = = ubicación.href.replace ("MLos siguientes son suplementos como referencia
jQuery determina si el navegador es un navegador móvil o basado en computadora salta automáticamente
Un código pequeño, el mismo sitio web salta a diferentes páginas para la visualización de dispositivos móviles y computadora.
Primero cargue el archivo jQuery.
$(function(){ var MobileUA = (function() { var ua = navigator.userAgent.toLowerCase(); var mua = { IOS: /ipod|iphone|ipad/.test(ua), //iOS IPHONE: /iphone/.test(ua), //iPhone IPAD: /ipad/.test(ua), //iPad ANDROID: /Android/.test(ua), // Windows de dispositivos Android: /windows/.test(ua), // Windows Device Touch_Device: ('OnTouchStart' en Window) || // Windows tableta: false, // tableta (iPad, Android, Windows) Smart_Phone: False // Smart Phone (iPhone, Android)}; mua.Android_tablet || });La sincronización de datos de las páginas web se requiere en el teléfono móvil
La copia del código es la siguiente:
<script type = "text/javaScript">
(function () {var ua = navigator.useragent.tolowercase (); var bisipad = ua.match (/iPad/i) == "iPad"; var bisiphoneos = ua.match (/iiphone os/i) == "iPhone OS"; var bisandroid = ua.match (/android/i) == "yid"; biswm = ua.match (/windows mobile/i) == "windows mobile"; if (bisipad || bisiphoneos || bisandroid || biswm) {window.location.href = "http://m.vevb.com/Adroid/game/826.html"}}););
</script>
El segundo método:
<Script language = "javaScript"> function mobile_device_detect (url) {var thisOS = navigator.platform; var os = new Array ("iPhone", "iPod", "iPad", "android", "Nokia", "Symbianos", "Symbian", "Windows Phone", "Phone", "Linux ARMV71", "Maui", "No conformado/1.0", "Windows CE", "Blackberry", "iemobile"); for (var i = 0; i <os.length; i ++) {if (Thisos.match (os [i])) {window.location = url; }} // Debido a que un número considerable de sistemas de teléfonos móviles no conoce la información, aquí hay una identificación especial temporal si (navigator.platform.indexof ('iPad')! = -1) {window.location = url; } // Esta parte se debe a que el núcleo de los teléfonos Android también es Linux // Sin embargo, Navigator.platform muestra información diferente, así que comience con el navegador, es decir, use la información navigator.appversion para hacer juicios var check = navigator.appversion; if (check.match (/linux/i)) {// x11 es la plataforma del navegador UC. Si hay otros navegadores especiales, también puede adjuntar las condiciones si (check.match (/mobile/i) || check.match (/x11/i)) {window.location = url; }} // class in_array function array.prototype.in_array = function (e) {for (i = 0; i <this.length; i ++) {if (this [i] == e) return true; } return false; }} mobile_device_detect ("http: //***.***.com"); </script>Nota aquí
mobile_device_detect ("http: //****.***.com"); // La dirección interior se completa en la dirección de su sitio web móvil.