Elxis CMS Forum
Support => General => Topic started by: armpouniotis on April 27, 2020, 16:57:31
-
Hi there !
I want to make a module_content, and inside that I want to display this (it is a script that displays current time):
<script>
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('txt').innerHTML =
h + ":" + m + ":" + s;
var t = setTimeout(startTime, 500);
}
function checkTime(i) {
if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10
return i;
}
</script>
</head>
<body onload="startTime()">
<div id="txt"></div>
Can I do that inside the text editor ?
Thank you in advance
Christos
-
No, and it is a very bad idea to insert javascript in editor. Put your javascript in an external js file and load it in your template. In module's html area put just the html.
$eDoc->addScriptLink('https://www.example.com/something/blahblah.js');
$eDoc->addNativeDocReady('startTime();');
-
It works better than I thought !
Thank you !
Christos