jquery-mobile - Phonegap 和 jquery mobile : a href -> Origin null is not allowed by Access-Control-Allow-Origin

标签 jquery-mobile cordova

我试图在多页文档中使用带有 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/

相关文章:

ios - Phonegap/Cordova ios 加载远程 url 如何在出错时回退到本地 index.html?

javascript - 是否可以从 jsperf 中删除损坏的修订版?

javascript - 内联 css 不适用于 JQM

javascript - 如何在选择选项中显示从数据库中获取的值

jquery - jQuery Mobile 中的弹出窗口未按预期工作,请提出建议

android - Ionic 应用程序因 braintree 插件而崩溃 - java.lang.NoSuchMethodError : No static method getFont

android - 使用 Phonegap 2.0.0 在 Android 和 iPhone 上共享 Twitter 和 Facebook

jquery-mobile - jQuery Mobile : Uncaught cannot call methods on checkboxradio prior to initialization; attempted to call method 'refresh'

执行此行时发生 Javascript Sencha cmd 应用程序构建错误

android - Cordova +安卓 : How to stop shrinking of screen if virtual keyboard is displayed?