Dear All, I am aware that there are setTimeOut and SetInterval within javascript but I am trying to achieve a countdown timer to then run a function with the countdown timer visible within my website and also dataset. I have reviewed the Wix Code examples of utilising postMessage and onMessage to communicate between page code and html however I am no further along if someone could help me with the code or provide other examples it would be great. I look forward to hearing from you. @Yisrael (Wix) $w.onReady(() =>{ $w("#html4").postMessage(timer); $w("#html4").onMessage((event)=>{ if(event.data.type === 'ready'){ $w("#html4").postMessage(timer); } function countdown(element, minutes, seconds) { // set time for the particular countdown var time = minutes*60 + seconds; var interval = setInterval(function() { var ctx = document.getElementById('#html4'); // if the time is 0 then end the counter if (time <= 0) { var text = "hello"; ctx.innerHTML = text; setTimeout(function() { countdown('clock', 0, 60); }, 2000); clearInterval(interval); return; } var minutes = Math.floor( time / 60 ); if (minutes < 10) minutes = "0" + minutes; var seconds = time % 60; if (seconds < 10) seconds = "0" + seconds; var text = minutes + ':' + seconds; ctx.innerHTML = text; time--; }, 1000); } countdown('clock', 0, 60); }); })
top of page
Important forum update
This forum is migrating to one unified Wix community forum starting July 26th, and will be read-only during the process.
![feature fixed.png](https://static.wixstatic.com/media/3bfa8a_f845e1016b8a49758acdd6edd6610c3b~mv2.png/v1/crop/x_0,y_2,w_852,h_508/fill/w_104,h_62,al_c,q_85,usm_0.66_1.00_0.01,blur_3,enc_auto/feature%20fixed.png)
Wishlist Page is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.
bottom of page
You can't embed HTML in a Wix Code page. WixCode understands all of Javascript, except for anything that accesses the DOM. This keeps the user from inadvertently "breaking" something. Accessing document elements such as div, span, button, etc is off-limits. The way to access elements on the page is only through $w. Therefore, innerHTML is invalid in Wix Code.
For more information, see the article Working with the HTML Component in Wix Code. You can also refer to the examples that use the HtmlComponent to see how it's done.