مع وصول 4G ، تكون مواقع الويب المحمولة خارج نطاق التحكم ، وتعايش الكمبيوتر الشخصي والمواقع الرسمية للهاتف المحمول. كيفية جعل الآخرين يزورون موقع الويب الرسمي للكمبيوتر الخاص بك والقفز مباشرة إلى موقع المحمول؟ أيها القراء الأعزاء ، يرجى إضافة الرمز! هنا يأتي!
تحديد ما إذا كان المتصفح هاتفًا محمولًا
<script type = "text/javaScript"> (function () {var rewriteUrl = function (url) {if (url) {var splits = url.split ("/") 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 = pathname = window.location.pathname ؛ if (url.indexof ("؟ pc") <0) {try {window.location.href = rewriteurl (url)} catch (e) {}}}}) () ؛ </script>لتحديد ما إذا كان المتصفح هو جهاز كمبيوتر ، انقلب إلى صفحة الكمبيوتر
<script> var prowser1 = {repions: function () {var u = navigator.useragent ، app = navigator.appversion ؛ return {// Mobile Terminal Browser إصدار معلومات الإصدار Trident: U.Indexof ('trident')> -1 ، // ie kernel presto: u.indexof ('presto')> -1 ، // opera kernel webkit: u.indexof ('AppleWebkit')> -1 ، // Apple and Google geeco: uT. U.Indexof ('khtml') == -1 ، // firefox kernel mobile: !! !! U.Match (/midp | symbianos | nokia | samsung | lg | nec | tcl | alcatel | bird | dbtel | dopod | philips | haier | lenovo | mot- | nokia | sonyericsson | sie- OS X/) ، // iOS Terte android: U.Indexof ('Android')> -1 || U.Indexof ('Linux' It a iPad WebApp: U.Indexof ('Safari') == -1 // هو الويب المفترض أن يبرز ، لا يوجد رأس وأسفل} () ، (Navigator.BrowserLanguage || navigator.language) .ToLowerCase ()} if (browser1.versions.mobile == false && prowser1.versions.ios == false && prowser1.versions.android == false && prowser1.versions.iphone == false && prowser1.versions.ipad == false) {// location.href = location.href.replace ("M." ، "www.") ؛ // إذا لم يكن الهاتف مفتوحًا ، فانقل إلى تنبيه صفحة الكمبيوتر ("PC") ؛} </script>فيما يلي مكملات للرجوع إليها
يحدد jQuery ما إذا كان المتصفح متصفحًا محمولًا أو قائمًا على الكمبيوتر يقفز تلقائيًا
رمز صغير ، يقفز موقع الويب نفسه إلى صفحات مختلفة لعرض الأجهزة المحمولة والكمبيوتر.
قم أولاً بتحميل ملف jQuery.
$ (function () {var mobileua = (function () {var ua = navigator.useragent.toLowerCase () ؛ var mua = {iOS: /ipod ophone|| |ipad/. /-antroid/.test(UA) ، // Android Windows: /windows/.test(ua) ، // Windows Device Touch_device: ('onTouchStart' in window) || // Windows Tablet: // tablet (iPad ، Android) Smart_Phone: False // Smart Phone (iPhone ، Android) ؛ || 'http://www.aaa.com/wap/index.html' ؛مطلوب مزامنة البيانات في صفحات الويب على الهاتف المحمول
نسخة الكود كما يلي:
<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" mobile/i) == "Windows Mobile" ؛ if (bisipad || bisiphoneos || bisandroid || biswm) {window.location.href = "http://m.vevb.com/android/game/826.html"}}) () ؛
</script>
الطريقة الثانية:
<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" ، "غير موثوق/1.0" ، "Windows CE" ، "Blackberry" ، "iEmobile") ؛ لـ (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 يعرض معلومات مختلفة ، لذلك ابدأ بالمتصفح ، أي استخدام معلومات navigator.appversion لجعل الأحكام var check = navigator.appversion ؛ 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) return true ؛ } إرجاع خطأ ؛ }} mobile_device_detect ("http: //*** .***.com") ؛ </script>لاحظ هنا
mobile_device_detect ("http: //***.***.com") ؛ // يتم ملء العنوان الداخلي على عنوان موقع الويب الخاص بك.