2012-07-11 2 views
4

여기에 설명 된대로 jquery 모바일이 뿌려진 작동하는 HelloWorld 전화 갭 프로그램이 있습니다 : http://jquerymobile.com/demos/1.1.0/docs/about/getting-started.html. 나는 간 리소스 공유 실험이에 약간의 자바 스크립트를 추가 :CORS + Android Webview가 장치에서 작동하지 않습니다 (에뮬레이터에서 작동)

<script> 
$(document).bind("pageinit", function() { 
    $.support.cors = true; 
    $.mobile.allowCrossDomainPages = true; 
    $.mobile.changePage("http://jquery.com"); 
}); 
</script> 

이 에뮬레이터 (2.3)에 좋은 작품은, jquery.com은 JQuery와 모바일 데모를 통해로드됩니다. 그러나 실제 2.3 Android 기기 (Cyanogen, Galaxy SII, Galaxy Player를 실행하는 T-mobile G2)에서는 changePage() 호출이 아무 것도하지 않습니다.

+0

y는 무엇입니까? 캐시 및 비동기 필드를? – Erol

답변

1

pageinit 대신 mobileinit을 시도하십시오. 바인딩 한 이벤트는 일반 jQuery이고 jQuery 모바일의 경우 초기화 이벤트는 mobileinit입니다.

The $.mobile.allowCrossDomainPages option must be set before any cross-domain request is made so we recommend wrapping this in a mobileinit handler.

4

pageinit 함수 내에서 $.mobile.changePage() 함수를 호출하는 것은 무한 루프가 발생해야하기 때문에 좋지 않은 것처럼 들립니다. $.mobile.changePage() 함수는 target 매개 변수로 지정된 페이지를 초기화하므로 $.mobile.changePage()을 호출 할 때마다 pageinit 이벤트도 발생합니다.

jQuery를 모바일이 초기화되기 전에 당신은 아마도 $.support.cors 변수를 덮어 mobileinit 이벤트에 바인딩 할

:

<script src="jquery.js"></script> 
<script> 
$(document).bind("mobileinit", function() { 
    $.support.cors = true; 
    $.mobile.allowCrossDomainPages = true; 
    $.mobile.changePage("http://jquery.com"); 
}); 
</script> 
<script src="jquery-mobile.js"></script> 

관련 문서 :

관련 문제