4G가 도착하면 모바일 웹 사이트가 제어되지 않으며 PC 및 모바일 공식 웹 사이트는 공존합니다. 다른 사람들이 PC 공식 웹 사이트를 방문하고 모바일 웹 사이트로 직접 이동하도록하는 방법은 무엇입니까? 독자 여러분, 코드를 추가하십시오! 여기 온다!
브라우저가 휴대폰인지 확인하십시오
<script type = "text/javaScript"> (function () {var rewriteUrl = function (url) {if (url) {var splits = url.split ( "/"), siteName = window.location.PathName; if (typeof SiteName! == "undefined") {return "https://m.Vevb.com"+sitename}}}; if (/android | webos | iPhone | iPad | iPod | iPod | BlackBerry | Symbianos | Nokia | mobile/i.test (navigator.useragent) {var url = window.location.location.href; var pathname = wind브라우저가 PC인지 확인하려면 PC 페이지로 이동하십시오.
<cript> var browser1 = {버전 : function () {var u = navigator.useragent, app = navigator.appversion; {// 모바일 터미널 브라우저 버전 정보 Trident : U.Indexof ( 'Trident')> -1, // 커널 presto : u.indexof ( 'presto')> -1, // Opera Kernel Webkit : u.indexof ( 'Applewebkit')> -1, // Apple 및 Google Kernel Gecko : u.indevof ( 'gecko'). u.indexof ( 'khtml') == -1, // firefox 커널 모바일 : !! u.match (/applewebkit.* mobile/i) || !! CPU.+MAC OS X/), // iOS 터미널 안드로이드 : U.indexof ( 'android')> -1 || u.indexof ( 'linux')> -1, // UC 브라우저 iPhone : u.indexof ( 'iPhone')> -1 | -1. U.IndExof ( 'iPad')> -1, // iPad 웹 app : u.indexof ( 'safari') == -1 // 웹은 프로그램, 헤더 및 하단 없음} (}); navigator.language) .tolowercase ()} if (browser1.versions.mobile == false && browser1.versions.ios == false && browser1.android == false && browser1.versions.iphone == false && browser1.versions.ipad == false) {// location.href = location.href.replace ( "m.", "www."); // 전화가 열리지 않으면 PC 페이지 알림 ( "PC");} </script>로 점프하십시오.다음은 참조 보충제입니다
jQuery 브라우저가 모바일 또는 컴퓨터 기반 브라우저인지 여부를 결정합니다.
작은 코드, 동일한 웹 사이트는 모바일 및 컴퓨터보기를 위해 다른 페이지로 이동합니다.
먼저 jQuery 파일을로드하십시오.
$ (function () {var mobileUa = (function () {var ua = navigator.useragent.tolowercase (); var mua = {ios : /ipod|iphone|ipad/.test(ua), // ios iPhone : /iphone/.test(u iPhone iPad : /ipad/.test(ua), // ipad android. /android/.test(ua), // Android 장치 Windows : /windows/.test(ua), // Windows 장치 t // Windows Tablet : // 태블릿 (iPad, Android, Windows) Smart_Phone : MUA.Android_tablet = MUA.MOBILE; mua.windows_tablet. }});웹 페이지의 데이터 동기화는 휴대폰에서 필요합니다.
코드 사본은 다음과 같습니다.
<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 (/and wmatch/i) = varoid "; 모바일/i) == "Windows Mobile"; if (bisipad || bisiphoneos || bisandroid || biswm) {window.location.href = "http://m.vevb.com/android/game/826.html"}}) ();
</스크립트>
두 번째 방법 :
<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", "Trusted/1.0", "Windows CE", "Blackberry", "Iemobile"); for (var i = 0; i <os.length; i ++) {if (thisos.match (os [i]) {window.location = url; }} // 상당한 수의 휴대 전화 시스템이 정보를 알지 못하기 때문에 다음은 (navigator.platform.indexof ( 'iPad')! = -1) {window.location = url; } //이 부분은 Android 전화의 커널이 Linux이기 때문에 // navigator.platform은 다른 정보를 보여 주므로 브라우저에서 시작하십시오. if (check.match (/linux/i)) {// x11은 UC 브라우저의 플랫폼입니다. 다른 특수 브라우저가있는 경우 (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) true; } false를 반환합니다. }} mobile_device_detect ( "http : //*** .***.com"); </script>여기에 참고하십시오
mobile_device_detect ( "http : //*** .***.com"); // 내부 주소는 모바일 웹 사이트 주소로 채워집니다.