I am using a Squarespace site with a specific template that uses the index page and sub pages as the contents of the index page. (Pages scroll one by one). I assume that the bindings are used by Squarespace to go to the corresponding page from the index page.
I added javascript to show the current time and update it every second (moment.js and moment-timezone). I update the time every second with SetInterval (function_name, 1000);
Time is updated correctly every second. However, this brings up a specific page, on which I am updating the time to keep focusing while trying to scroll up or down (this happens every second). So if I try to scroll up or down from that particular page where the time is being updated, it will automatically scroll to that page every second!
It seems that every second an event occurs that causes this. The actual function that I call every second is as follows:
function showLocalTime() { var momentLondon = moment().tz("Europe/London").format('HH:mm:ss z'); // The location label HTML var locationHTML = '<strong>Location</strong><br>'; // The HTML string for london, England var londonHTML = 'London, England'; $( "p:contains('London, England')" ).html(locationHTML + londonHTML + ' (' + momentLondon + ')'); }
Therefore, all I do is change the innerHTML of a specific HTML element to show the current time.
I call the above function as follows:
<script> $(function() { document.addEventListener("DOMSubtreeModified", function(){ return;}); window.setInterval(showLocalTime, 1000); </script>
However, as I said, calling the above function again through SetInterval forces the web page to automatically track this section of the web site (the "Contact Us" page) every second !!.
I see that the DOMSubtreeModified event is triggered, which is fired every time I call the function above. I added a custom listener to the DOMSubtreeModified event, but still, I still get the same problem.
Maybe this is due to some kind of redrawing event? Anyway, I cannot find the problem, and I cannot solve this problem.
Any help would be appreciated!
thanks