简体   繁体   English

Cordova / Phonegap注入javascript返回值3.4.0

[英]Cordova / Phonegap inject javascript return value 3.4.0

I am creating a cordova / phonegap app using cordova 3.0.4 我正在使用cordova 3.0.4创建一个cordova / phonegap应用

I am trying to use the inject javascript function to insert a function then get the return value. 我正在尝试使用注入javascript函数插入一个函数,然后获取返回值。 But nothing shows up in the alert box. 但是警报框中什么也没有显示。 this is my code 这是我的代码

<!DOCTYPE html>
<html>
<head>
<title>InAppBrowser.executeScript Example</title>

<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">

// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);

// Global InAppBrowser reference
var iabRef = null;

// Inject our custom JavaScript into the InAppBrowser window
//
function addFeebackFunction() {
    iabRef.executeScript(
        {code: "var evaluateFeedback = function(){return 'Done';};"},
        function(data) {
            alert(data);
        }
    );
    //iabRef.close();
}

function iabClose(event) {
     iabRef.removeEventListener('loadstop', addFeebackFunction);
     iabRef.removeEventListener('exit', iabClose);
}

// Cordova is ready
//
function onDeviceReady() {
     iabRef = window.open('http://{ipaddress}/test/', '_blank', 'location=no');
     iabRef.addEventListener('loadstop', addFeebackFunction);
     iabRef.addEventListener('exit', iabClose);
}

</script>
</head>
<body>
  <h1>Mobile App</h1>
</body>
</html>

I it returns an array of length 1, but when i alert the value of data[1] it is a value of null. 我返回一个长度为1的数组,但是当我警告data [1]的值时,它的值为null。

Does anyone have any idea? 有人有什么主意吗?

Thanks in advance 提前致谢

您是说它返回一个长度为1的数组,因此data [1]绝对为空,因为数组键以零开头,因此请尝试data [0]。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM