I am using a Squarespace website with a specific template that uses an index page and sub pages as the contents of the index page. (The pages are scrollable one after the other). I guess anchors are being used by Squarespace to scroll to relevant page from the index page.
I added a javascript to show the current time and update it every second (moment.js and moment-timezone). I am updating the time every second with SetInterval(function_name,1000);
The time is updating correctly every second. However, this causes the particular page where I am updating the time to keep coming into focus when trying to scroll up or down (it happens every second). So If i try to scroll up or down from that particular page where the time is updating, it keep scrolling automatically back to that page every second!!.
It seems there is an event triggering every second which causes this. The actual function that I am calling every second is the following:
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 am doing is changing the innerHTML of a particular HTML element to show the current time.
I am calling the above function as follows:
<script>
$(function() {
document.addEventListener("DOMSubtreeModified", function(){
return;});
window.setInterval(showLocalTime, 1000); // update it periodically
});
</script>
However, as I said, the repeated call to the above function through SetInterval causes the webpage to keep autoscrolling to this section of the website (Contacts Page) every second!!.
I can see that there is an event DOMSubtreeModified being triggered every time I call the above function. I added a custom listener to DOMSubtreeModified event, but still I am still getting the same issue.
It could be that this is due to some sort of redraw event? Anyway, I cannot seem to locate the issue and I am unable to overcome this problem.
Any help would be appreciated!!
Thanks