简体   繁体   English

无法在Cordova 3.5上更改index.html文件

[英]Can't change the index.html file at Cordova 3.5

I'm using Cordova 3.5 for a project and I'm not able to change the index.html file. 我正在使用Cordova 3.5进行项目,但无法更改index.html文件。 If I change that file, the device.ready -event is not firing. 如果我更改该文件, device.ready -event不会触发。

The (standard) index.html file looks like that: (标准)index.html文件如下所示:

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <meta name="msapplication-tap-highlight" content="no" />
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting too Device</p>
                <p class="event received">Device is Ready</p>
                asfasf
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript">
            app.initialize();
        </script>
    </body>
</html>

When I delete the div s with id "deviceready", "event listening" or "event received" the device.ready event is not firing anymore. 当我删除div与S id “deviceready”,“侦听事件”或“事件受了” device.ready事件不烧了。

What causes this problem? 是什么导致此问题?

EDIT The index.js looks like: 编辑 index.js看起来像:

var app = {
    // 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() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicitly call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
        alert("JO");
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    }
};

When you remove those elements, the app.receivedEvent() will throw an error because it's trying to manipulate elements that don't exist. 当您删除这些元素时, app.receivedEvent()会引发错误,因为它试图操纵不存在的元素。 This error is thrown before your alert() call. 在您的alert()调用之前引发此错误。

Remove app.receivedEvent('deviceready'); 删除app.receivedEvent('deviceready'); from app.onDeviceReady() and it should work. app.onDeviceReady() ,它应该可以工作。

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

相关问题 科尔多瓦仅呈现index.html内容 - Cordova renders only the index.html content 我无法修复 Heroku“找不到所需的文件,名称:index.html”错误 - I can't fix Heroku "Could not find a required file, Name: index.html" error 如何更改 index.html 中 body 的背景颜色? - How can I change the background color of the body in index.html? SailsJS无法访问资产/应用中的index.html - SailsJS can't access index.html located in assets/app index.html和路径更改后无法启动localhost - Can't launch localhost after index.html and path is changed 如何将文件 vuejs 组件导入 index.html? - how can I import a file vuejs component into index.html? 如何在 Svelte 中重命名 index.html 文件? - How can I rename index.html file in Svelte? Reactjs-router-dom和cordova始终直接指向file:///android_asset/www/index.html - Reactjs-router-dom and cordova always direct to file:///android_asset/www/index.html 当我更改服务器 index.html 文件的方式时,哪些路径不起作用? - What aren't my paths working when I change the way I server my index.html file? 我不能 append 在 js 文件中创建的 div<section> ,在我的 index.html 中的网格内</section> - I'm can't append a div created in js file inside a <section>, whitch is inside a grid, in my index.html
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM