Skip to content
document.addEventListener("DOMContentLoaded", function() {
const tab1 = document.getElementById('top-tab-1');
const tab2 = document.getElementById('top-tab-2');
// 1. Read the url parameter marker (?view=exhibitor) directly from the address bar
const urlParams = new URLSearchParams(window.location.search);
let currentView = urlParams.get('view');
// 2. If no URL parameter exists yet, check the page name to determine the default section
const currentPath = window.location.pathname;
// Auto-detect explicit Exhibitor pages (Add any explicit exhibitor slugs here)
if (!currentView) {
if (currentPath.includes('/advanced-engineering-exhibitors') ||
currentPath.includes('/exhibit') ||
currentPath.includes('/sponsorship')) {
currentView = 'exhibitor';
} else {
currentView = 'visitor'; // Default fallback
}
}
// 3. Highlight the correct top tab based on the final decision
if (currentView === 'exhibitor' && tab2) {
if (tab1) tab1.classList.remove('active-tab');
tab2.classList.add('active-tab');
} else if (tab1) {
if (tab2) tab2.classList.remove('active-tab');
tab1.classList.add('active-tab');
}
// 4. Force all navigation links to remember this view state across page reloads
// This dynamically appends ?view=exhibitor or ?view=visitor to links before they are clicked
if (currentView) {
document.querySelectorAll('a').forEach(link => {
const href = link.getAttribute('href');
// Avoid altering external domains, anchor tags, or javascript links
if (href && href.startsWith('http') && href.includes(window.location.hostname) && !href.includes('#')) {
try {
const linkUrl = new URL(href);
linkUrl.searchParams.set('view', currentView);
link.setAttribute('href', linkUrl.toString());
} catch (e) {
// Fail-safe for malformed URL strings
}
} else if (href && href.startsWith('/') && !href.includes('#')) {
// Handle relative root links (e.g., /our-vision/)
const separator = href.includes('?') ? '&' : '?';
link.setAttribute('href', href + separator + 'view=' + currentView);
}
});
}
});