PhoneGap的科尔多瓦3.1.0 inAppBrowser的EventListener不工作 [英] PhoneGap Cordova 3.1.0 inAppBrowser EventListener not working
问题描述
我开始使用现在科尔多瓦3.1.0。我使用命令行来生成一个项目,然后修改现有的code。结果
我复制并粘贴从官方网站下code测试。
I'm starting to use Cordova 3.1.0 now. I use command line to generate a project and then modify the existing code.
I copy and paste the following code from official website to test.
<!DOCTYPE html>
<html>
<head>
<title>InAppBrowser.addEventListener Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
var ref = window.open('http://apache.org', '_blank', 'location=yes');
ref.addEventListener('loadstart', function(event) { alert('start: ' + event.url); });
ref.addEventListener('loadstop', function(event) { alert('stop: ' + event.url); });
ref.addEventListener('loaderror', function(event) { alert('error: ' + event.message); });
ref.addEventListener('exit', function(event) { alert(event.type); });
}
</script>
</head>
<body>
</body>
</html>
这是行不通的。有没有警报。然后,我增加了一个按钮尝试解雇的事件。
This doesn't work. There are no alert. Then I added a button to try to fire the events.
<!DOCTYPE html>
<html>
<head>
<title>InAppBrowser.addEventListener Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
$("#btn").click(function(){
var ref = window.open('http://apache.org', '_blank', 'location=yes');
ref.addEventListener('loadstart', function(event) { alert('start: ' + event.url); });
ref.addEventListener('loadstop', function(event) { alert('stop: ' + event.url); });
ref.addEventListener('loaderror', function(event) { alert('error: ' + event.message); });
ref.addEventListener('exit', function(event) { alert(event.type); });
});
}
</script>
</head>
<body>
<button id="btn">trigger</button>
</body>
</html>
这一次,它与第二次。这意味着,当我点击按钮,第一次它不工作。但它工作在当我点击按钮的第二次。在那之后,我用控制台日志的回调函数来调试中。的日志未在第一时间(出现在第二次和第三,第四......)出现了。结果,
我真的不知道为什么会这样。我跟着从官方网站上的所有步骤。创建项目,安装插件,建筑等。结果
可能有人给我一个忙吗?
This time, it works with second time. It means, it doesn't work when I click the button first time. But it works at the second time when I click the button. After that, I use console log inside the callback function to debug. The logs were not appeared at the first time (appeared at the second time and third, forth....).
I don't really know why this happened. I followed all steps from official website. Creating project, installing plugin, building and so on.
Could someone give me a hand?
推荐答案
它看起来像它与过去的PhoneGap /科尔多瓦版中的问题3.1.0。
It looks like it's a problem with the last phonegap/cordova version 3.1.0.
https://groups.google.com/forum/#!topic/ PhoneGap的/ e5_5unC2fYs
尝试旧版本。
这篇关于PhoneGap的科尔多瓦3.1.0 inAppBrowser的EventListener不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!