![](/img/trans.png)
[英]Android onDownloadStart() in WebView work on Device but not on emulator
[英]CORS + Android Webview, doesn't work on device (but does on emulator)
我有一個工作正常的HelloWorld phonegap程序,其中的jquery mobile如下所示: http : //jquerymobile.com/demos/1.1.0/docs/about/getting-started.html 。 我為此添加了一些JavaScript,以嘗試跨源資源共享:
<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()調用沒有任何作用。
調用$.mobile.changePage()
的函數內pageinit
像一個壞主意功能的聲音,因為這應該引起無限循環。 $.mobile.changePage()
函數初始化指定為target
參數的頁面,因此,每次調用$.mobile.changePage()
,也會觸發pageinit
事件。
您可能想綁定到mobileinit
事件以在初始化jQuery Mobile之前覆蓋$.support.cors
變量:
<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>
相關文件:
嘗試使用mobileinit
而不是pageinit
。 因為綁定到的事件是普通jQuery,而對於jQuery mobile,則初始化事件為mobileinit。
The $.mobile.allowCrossDomainPages option must be set before any cross-domain request is made so we recommend wrapping this in a mobileinit handler
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.