我试图在多页文档中使用带有 phonegap 的 jquery mobile。
尝试使用基本 href 文档中的链接,给出了 Origin null is not allowed by Access-Control-Allow-Origin 错误,这很烦人。
这是因为索引页面是通过 file://而不是 http://引用的,webkit 将其解释为 origin null。有没有人让 jquery mobile 和 phonegap 在多页面环境中工作?如果是这样,你怎么做?如果您将 rel=external 添加到 href 标签,链接将起作用,但当然所有的转换都会丢失。
在堆栈溢出或 Internetz 上找不到有关此特定问题的任何信息。
<!DOCTYPE HTML>
<html>
<head>
<title>PhoneGap</title>
<script type="text/javascript" charset="utf-8" src="phonegap-1.2.0.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script>
$(document).bind( "mobileinit", function(){
//alert("mobileinit fired");
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
});
</script>
<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
<script type="text/javascript">
function onDeviceReady() {
navigator.network.isReachable("google.com", reachableCallback, {});
}
// Check network status
function reachableCallback(reachability) {
// There is no consistency on the format of reachability
var networkState = reachability.code || reachability;
var states = {};
states[NetworkStatus.NOT_REACHABLE] = 'No network connection';
states[NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK] = 'Carrier data connection';
states[NetworkStatus.REACHABLE_VIA_WIFI_NETWORK] = 'WiFi connection';
if (networkState != 0) online = true;
}
var online = navigator.onLine || false;
$(document).ready(function() {
$(document).bind('deviceready', function(){
onDeviceReady()
})
// Your main code
})
//Now if you about to make an AJAX call to load up some dynamic data, you can easily check to see if you're online
if(online) {
} else {
}
</script>
</head>
<body>
<h1>Welcome to PhoneGap</h1>
<a href="edit.html">Edit html</a>
</body>
</html>
最佳答案
这是official documentation关于如何做你正在寻找的...
希望这可以帮助!
关于jquery-mobile - Phonegap 和 jquery mobile : a href -> Origin null is not allowed by Access-Control-Allow-Origin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8463886/