gpt4 book ai didi

android - CORS + Android Webview,不适用于设备(​​但适用于模拟器)

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:51:45 24 4
gpt4 key购买 nike

我有一个有效的 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() 调用不执行任何操作。

最佳答案

pageinit 函数中调用 $.mobile.changePage() 函数听起来不是个好主意,因为这会导致无限循环。 $.mobile.changePage() 函数初始化指定为 target 参数的页面,因此每次您调用 $.mobile.changePage()您还触发了一个 pageinit 事件。

您可能希望绑定(bind)到 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>

相关文档:

关于android - CORS + Android Webview,不适用于设备(​​但适用于模拟器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11440677/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com