Software Archive
Read-only legacy content
17061 Discussions

<body> tag disappear automatically!

Ram_Pawar
Beginner
861 Views

Hello friends, 

I'm making one small app, in which I created a function to show current time of device, calling it on body load, and using it in div. But problem is that once I open design (after writing code), <body onload="startTime()"> disappears, and time doesn't work, And if I go directly from code to emulator, time works perfectly. 
 

Here is code of function: 

function startTime() {
    var today=new Date();
    var h=today.getHours();
    var m=today.getMinutes();
    var s=today.getSeconds();
    m = checkTime(m);
    s = checkTime(s);
    document.getElementById('horas_atuais').innerHTML = h+":"+m+":"+s;
    var t = setTimeout(function(){startTime()},500);
}

function checkTime(i) {
    if (i<10) {i = "0" + i};  // add zero in front of numbers < 10
    return i;
}

I'm starting this function when body loads :

<body onload="startTime()">

And showing it in div: 

<div class="container" style="width: 100%; position: relative; height: auto; text-align: right;"
            data-appbuilder-object="container">
            
            <div id="horas_atuais" class="text_item" data-appbuilder-object="text">Horas </div>

</div>

Thanks! ~(^_^)~

0 Kudos
4 Replies
Elroy_A_Intel
Employee
861 Views

When using the Intel XDK App Designer (Design) tool, any manual edits to the source Code will be overwritten in the index.html by the tool. If you go to the Design panel from the Code panel then add a UI element, the code is regenerated removing all of the manual edits.

0 Kudos
Ram_Pawar
Beginner
861 Views

And isn't there any way to fix the manual code? 
Thanks! 

0 Kudos
Elroy_A_Intel
Employee
861 Views

At this moment, there isn't any solutions to address this issue.

0 Kudos
PaulF_IntelCorp
Employee
861 Views

Instead of inserting JavaScript into the html file, put it in a separate JS file and add an ID to the tag of interest. Then, in your JS code, use something like this to add your event handler:

var el ;

el = document.getElementById("id_startTime") ;
el.addEventListener("load", startTime, false) ;

 

0 Kudos
Reply