Elxis CMS Forum

Support => General => Topic started by: armpouniotis on April 27, 2020, 16:57:31

Title: Display scripts in a module content
Post 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
Title: Re: Display scripts in a module content
Post by: datahell on April 27, 2020, 21:21:15
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();');
Title: Re: Display scripts in a module content
Post by: armpouniotis on April 27, 2020, 22:36:44
It works better than I thought !

Thank you !

Christos