2016-05-17 138 views
1

我正在做phonegap应用程序,我无法在index.html和inappbrowser窗口之间共享数据。我尝试这个代码,但它不为我工作。在phonegap和inappbrowser之间共享数据

function addUsuario(){ 
    var fnac = document.getElementById("fnac").value; 
    var direccion = (document.getElementById("direccion").value).replace(/\s/g,'%20'); 
    var descripcion = (document.getElementById("descripcion").value).replace(/\s/g,'%20'); 
    //localStorage.setItem('"+direccion+"', direccion); 


    var ref = window.open('./geo.html', '_blank'); 
    ref.addEventListener("loadstart", function() { 
    var dire=document.getElementById("direccion").value; 
    ref.executeScript({ 
     code: "alert("+dire+");" 
    }); 
}); 

    setTimeout(function() { 

     var lat = localStorage.getItem('lat'); 
     var lng = localStorage.getItem('lng'); 
     alert(lng); 

     $('#datos').load("http://192.168.1.173/PHP_BS/mod_usuario.php?usuario=" + user + "&token=" + token+"&fnac="+fnac+"&dire="+direccion+"&descripcion="+descripcion+"&latitud="+lat+"&longitud="+lng); 

     ref.close(); 
    }, 11500); 


    }

我也尝试用localStorage的,但只有共享数据从inappbrowser到index.js但不能从index.js到inappbrowser。

回答

0

尝试这样的:

在你geo.html页:

<script> 
    function onReceiveData (serialisedData) { 
    var data = JSON.parse(serialisedData); 
    alert('received some data!'); 
    console.log(data); 
    // Do something with the data 
    } 
</script> 

在你科尔多瓦代码:

var ref = window.open('./geo.html', '_blank'); 
ref.addEventListener('loadstop', function() { 
    var params = {foo: 1}; 
    // Since executeScript works with a string, we need to serialise the data we send. 
    ref.executeScript({code: "onReceiveData(" + JSON.stringify(params) + ")"}); 
}); 
+0

非常感谢您的回答,但我不工作没有事件工作的警报。我会尽你所有的步骤。 – user3139428

+0

任何错误或其他信息来调试该问题? –

+0

我们正在使用手机应用程序,我们使用Facebook登录,因此无法使用浏览器进行调试。我们唯一的信息是不工作,警报不出现 – user3139428