I need to implement a functionality on my webpage where two tabs can be switched using Javascript, while also updating the URL with an anchor (e.g. page.html#tab1
) for bookmarking purposes.
The default setup has the tab contents in separate divs stacked vertically, and the anchor tag helps navigate to the correct one when JS is disabled.
When JS is enabled, CSS classes are applied to create tab-like behavior. Clicking on each tab should switch to the corresponding anchor, but without scrolling to it. The challenge arises when preventing the URL from changing to include the anchor if we return false from the onclick function.
Is there a way to update the browser URL to page.html#tab1
without causing the page to scroll to #tab1
?