PhoneGap Cordova 3.1.0 inAppBrowser EventListener无法正常工作
我现在开始使用Cordova 3.1.0。 我使用命令行生成项目,然后修改现有代码。
我从官方网站复制并粘贴以下代码进行测试。
InAppBrowser.addEventListener Example // 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); }); }
这不起作用。 没有警报。 然后我添加了一个按钮来尝试触发事件。
InAppBrowser.addEventListener Example // 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); }); }); }
这次,它第二次工作。 这意味着,当我第一次点击按钮时,它不起作用。 但是当我点击按钮时它第二次起作用。 之后,我在回调函数中使用控制台日志进行调试。 原木没有出现在第一次(第二次出现,第三次出现,第四次……)。
我真的不知道为什么会这样。 我从官方网站上了解了所有步骤。 创建项目,安装插件,构建等。
有人可以帮我一把吗?
看起来这是最后一个phonegap / cordova版本3.1.0的问题。
https://groups.google.com/forum/#!topic/phonegap/e5_5unC2fYs
试试旧版本。
我遇到了同样的问题。 经过进一步调查,我发现这些事件并未在模拟器/浏览器中触发,但在我进行测试的Nexus 7设备上被解雇了。 希望有所帮助!
- 从Phonegap使用ASP.NET Web服务
- 代码无法在Phonegap应用程序-Android上运行
- Android + PhoneGap + jQuery Mobile上的水平可滚动图像
- 无法从第二个包含的js文件中的第一个包含的javascript文件调用函数
- 如何在一个html文件中将pageinit用于多个data-role = page
- 使用Jquery Mobile进行XML解析
- Jquery ajaxpost不适用于iPhone和Android
- 为什么jQuery Mobile 1.1-rc1使用.gif加载图标(再次)?
- 如何在PhoneGap / Android中实现DATE PICKER?