HTMLSnippet not working?

0
My HTML Snippet is set to Javascript, but the content is not evaluated. I cannot find any debugging logs in the developer tools. However, I have noticed that the number of snippets is incremented for each page refresh,   What is wrong here?   My javascript content is: // Function to save the scroll positionfunction saveScrollPosition() {   localStorage.setItem('scrollPosition', window.scrollY);}// Function to load the scroll positionfunction loadScrollPosition() {   const scrollPosition = localStorage.getItem('scrollPosition');   if (scrollPosition !== null) {       window.scrollTo(0, parseFloat(scrollPosition));   }}// Save scroll position on scroll eventwindow.addEventListener('scroll', saveScrollPosition);// Load scroll position on page loadwindow.addEventListener('load', loadScrollPosition);
asked
4 answers
2

Not sure in what version of mendix you are working but I would always advise to use javascript actions instead of the HTMLSnippet widget, that way you are sure it will fire and its more easily debuggable. If you need to fire it on page load you can use the Events widget to fire a nanoflow with the javascript action.

 

Also once you set that up correctly and it still doesnt work you can add the line "debugger;" somewhere in your code and if you run it then locally and open your console.log when the script is fired you can debug the javascript in the console.

answered
0

Have you tried to turn on the 'Refresh' fields shown in the picture below?

image.png

answered
0

@Hunter Koppen. Thank you, I will try this

@Vinicius Strugato Amrbosio.

Yes thank you,  I have already tried this! Still not working!

answered
0

Thanks to Hunter Koppen I can assure, that the javascript is executed.

I have noticed though, zooming and scrolling does not change anything in the 

window properties? For example window.scroll>, window.innerWidth values are not changed when I zoom in the page or scroll down.

Can this be an issue with additional corporate styling in the page?

 

answered