function update_kepware_data_table() { let kepwareTab = null; // Check if the tab is already open by checking localStorage if (localStorage.getItem('kepware_tab_open') === 'true') { const tabURL = localStorage.getItem('kepware_tab_url'); kepwareTab = window.open(tabURL, '_blank'); } else { // Open a new tab and store the URL in localStorage kepwareTab = window.open('/scheduler_assistant/global_API_endpoint/kepware_SQL_engine.php', '_blank'); localStorage.setItem('kepware_tab_open', 'true'); localStorage.setItem('kepware_tab_url', kepwareTab.location.href); } setInterval(() => { if (kepwareTab) { kepwareTab.location.reload(); // Reload the tab every 2 seconds } }, 2000); // Add an event listener to handle when the tab is closed window.addEventListener('beforeunload', () => { // Clear the tab state from localStorage when the window is closed localStorage.removeItem('kepware_tab_open'); localStorage.removeItem('kepware_tab_url'); }); } update_kepware_data_table();