2014-04-25 3 views
3

기존 웹 페이지에 대한 모바일 사이트를 만들었습니다. 모바일 폴더 에 코드를 넣었습니다. www.testing.com/mobile과 같이 작동합니다.모바일 사용자를 모바일 페이지로 리디렉션하는 방법

하지만 내가해야 할 일은 사용자가 모바일에서 방문한 경우 모바일 페이지로 리디렉션되어야하고 웹에서 사용자가 방문하면 기본 페이지로 이동해야합니다.

여기 내가 사용 :

<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0" /> 

페이지에 맞게하지만 URL을 브라우저 에이전트 또는 기타 방법으로이

을 수행하는 방법에 모바일 m.tesing.com처럼 보여줍니다. 감사.

$(document).ready(function() {   
    if($('#some-element').css('display')=='none' { 
     window.location.replace("http://m.tesing.com"); 
    //or window.location = "http://m.tesing.com";  
    } 
}); 
+0

확인 [this] (http://stackoverflow.com/questions/1118581/redirect-mobile-devices-to-alternate-version-of-my-site) 대답. – miltos

+0

방법에는 여러 가지가 있지만 최선의 방법은 없습니다. –

+0

Google은 친구입니다. https://www.google.fr/search?q=php+detect+mobile&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:fr:official&client=firefox-a&channel=sb&gfe_rd= cr & ei = -R5aU4X9JabR8gfq54CwCA – fluminis

답변

1

다운로드이 detectmobile.js 및합니다

if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 
window.location.replace("http://m.tesing.com"); 
//or window.location = "http://m.tesing.com"; 
} 

또는 CSS와 다른 기술

/* Smartphones ----------- */ 
@media only screen and (max-width: 760px) { 
    #some-element { display: none; } 
} 

jQuery를 대신 jQuery를 사용

0

당신은 그것을 감지하는 간단한 자바 스크립트를 사용할 수 있습니다 머리 태그가 바뀝니다

,363,210
<head> 
       <script src="detectmobile.js"></script> 
       <script> 
         try { 
           // This is the URL where mobile 
           detectmobile.defaultMobileURL = "http://m.testing.com"; 
           detectmobile.process(); 
         } catch(e) { 
           // Make sure that in the fault modes 
           // we do not interrupt execution of other Javascript code 
         } 
       </script> 
     </head> 
0

사용해서 모바일 기기를 검출하고,이 코드는

<script language="javascript"> 
     if(/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) 
     { 
     window.location = "http://m.domain.com"; 
     } 
    </script> 

는 매치가 발견되는 경우에있어서 문자열에서 일치 테스트하기 위해 사용되어왔다() 시험 후 리디렉션 걸리는

리디렉션 장소. 이 코드를 기본 index.php 페이지 맨 위에 추가하십시오.

를 사용하여 모바일의 index.php에이 코드를 다시

<script language="javascript"> 
     if(!/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) 
     { 
     window.location = "http://testing.com"; 
     } 
    </script> 

당신이 하위 도메인을 만들어야 할 것이다 m.testing.com에 관해서는 리디렉션합니다.

관련 문제