webworks ready函数没有触发

时间:2014-03-26 19:27:44

标签: javascript jquery blackberry-webworks

我只有一个简单的网页工作页面,但我的代码没有解雇。加载功能警报会触发,但不会触发webworksready功能。我不确定我做错了什么。我认为这可能是js的一个问题,所以我直接指向webworks.js文件本身。

<html>
<head>
    <title></title>
    <link  rel="stylesheet" type="text/css" href="css/bbui.css">
    <script type="text/javascript" src="js/bbui.js"></script>
    <script type="text/javascript" src="js/webworks.js" ></script>
    <script type="text/javascript">
    window.addEventListener("load", function(e) {
        alert("load function");
        document.addEventListener("webworksready", function(){
            alert("Im in web works ready function");
        });
    }, false);
    </script>
</head>
<body>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您使用的是哪种SDK?您粘贴的代码适用于WebWorks v1,它对我来说是正确的。如果是这样,您是在设备/模拟器上还是在浏览器中进行测试?如果您只是在Chrome中进行测试,则不应触发此事件。

如果你正在使用新的WebWorks 2(由Cordova提供支持),事情就会发生一些变化。你会做这样的事情......

<html>
<head>

<!-- cordova -->
<script src="cordova.js"></script>

<!-- initialization -->
<script type="text/javascript">
    Application.initialize();
</script>

<!-- cordova code, usually in another file, not inline, but either way... -->
<script>


var Application = {

    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },

    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        blackberry.event.addEventListener('deviceready', this.onDeviceReady, false);
    },

    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicity call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        Application.receivedEvent('deviceready');

        // this is now, essentially your webworks ready function.

    },

    // Update DOM on a Received Event
    receivedEvent: function(id) {
        console.log('Received Event: ' + id);
    }
};

</script>