2017-10-02 16 views
0

condizionale 자동 리다이렉트 URL을 작성 중이지만 작동하지 않습니다. 이 중 아무도 작동하지, 왜다른 URL에서 자동 리디렉션하는 방법은 무엇입니까?

<script> 
     function mobileDevice() 
     { 
     $type = $_SERVER[‘HTTP_USER_AGENT’]; 
     if(strpos((string)$type, “Windows Phone”) != false || strpos((string)$type, “iPhone”) != false || strpos((string)$type, “Android”) != false) 
     return true; 
     else 
     return false; 
     } 
     if(mobileDevice() == true) 
     header(‘Location: https://www.organization.org/mobile/index_mobile.htm‘); 
</script> 

나는 아직 발표로

<script type="text/javascript"> 
     if (screen.width <= 414) { 
     document.location = "index.htm"; 
     <script language=javascript> 
    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { 
     location.replace("https://www.organization.org/mobile/index_mobile.htm"); 
    } 
      </script> 
     } 
    </script> 

: 나는 두 가지 방법으로 시도?

답변

1

일반 Javascript에서는 리디렉션 할 방법 대신 값 위치를 지정해야합니다. 메서드를 대체하여 URL 변경 기록을 저장하지 않습니다.

window.location = "https://www.organization.org/mobile/index_mobile.htm"; 

두 번째 방법으로 두 개의 태그를 중첩합니다. 올바른 코드는 다음과 같습니다

<script type="text/javascript"> 
     if (screen.width <= 414) { 
     document.location = "index.htm"; 
     if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { 
      location.replace("https://www.organization.org/mobile/index_mobile.htm"); 
     } 
     } 
</script> 
+0

내가 함께하려고하면 : 어쨌든 작동하지 않습니다. –

+1

스크립트 블록 내에 메타 태그를 삽입 할 수 없습니다. 이것은 어떻게 작동하지 않습니다. 메타 태그는 head 태그 안에 있어야하며 실행될 코드와 함께 스크립트 태그를 추가 할 수 있지만 그 안에 자바 스크립트 만 있습니다. ' ' – jmtalarn

+0

오 ... 그게 이유입니다. 정말 고맙습니다! –