PhoneGap Cordova 3.1.0 inAppBrowser EventListener not workin
PhoneGap Cordova 3.1.0 inAppBrowser EventListener not working
我现在开始使用Cordova 3.1.0。我使用命令行生成一个项目,然后修改现有代码。
我从官方网站复制并粘贴以下代码进行测试。
<!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>
这行不通。没有警报。然后我添加了一个按钮来尝试触发事件。
<!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>
这一次,它与第二次有效。这意味着,当我第一次单击按钮时它不起作用。但是当我单击按钮时,它可以在第二次工作。之后,我在回调函数中使用控制台日志进行调试。日志第一次没有出现(第二次出现,第三次出现......
我真的不知道为什么会这样。我遵循了官方网站上的所有步骤。创建项目,安装插件,构建等。
有人可以帮我一把吗?
我遇到了同样的问题。在进一步调查中,我发现事件没有在模拟器/浏览器中触发,而是在我进行测试的 Nexus 7 设备上触发。希望对您有所帮助!
看起来这是
最后一个Phonegap/cordova版本3.1.0的问题。
https://groups.google.com/forum/#!topic/phonegap/e5_5unC2fYs
尝试旧版本。
相关文章:
- jQuery is not loaded
- AngularJS JSON not arriving php
- $rootScope not working
- reactRedux is not defined
- jQuery document.ready not working
- Javascript/Jquery Blob not showing Chrome PDF
- ReferenceError: not defined
- ReferenceError: cordova is not defined @ng-cordova.min.js:7
- Javascript getElementsByTagName not working?
- jQuery's trim()的前缀为not运算符
- Javascript - element.childNodes does not see an append.newch
- SemanticUI模态not onDeny/onApprove事件未激发
- WebkitTransform not fluent
- JQuery.val( ) not working
- Tomcat websocket is not working
- :not选择器不适用于ul类-备选方案
- Javascript JSON.parse not working
- NodeJS Multer is not working
- PhoneGap Cordova 3.1.0 inAppBrowser EventListener not workin
- eventListener is not triggering